473,394 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Q: Java source and directory structure - 'standard way' ?

Ever have one of those days when you're not sure if it's you who's gone
mad, or the rest of the world?

I have an Open Source project on SourceForge for communication with YSMG
- Yahoo's IM protocol. I keep the project source in three directories,
based upon the code's function: one for the network API code itself, one
for the support APIs (basic chat spam filtering, Swing models, rich text
decoders, etc), and one for the test client built using the network API.

When I compile I use the -d option on Sun's SDK... the compiler builds
the necessary directory tree (if not already there from a previous build)
and places the class files into it.

One or two users have complained that the source is in the wrong direct-
ories and it won't compile. One guy helpfully rearranged the source tree
and mailed me a zip file - telling me this is the 'standard way' to store
Java source.

What they do is they build the package directory tree by hand, place
their .java files into the appropriate directories, and then just
"javac *.java" in each directory of the tree. The result is that, in
the absense of a specified output directory, the class files end up
right next to the source files - but this works because the source
code directory structure has been created to mirror the package names.

This isn't the first time I've seen this done - I've noted a programmer
where I work does the same thing! And although it works, to me it is
less than ideal. I have a hard time accepting that this is the 'standard
way', for several reasons:

1) The compiler should be responsible for organising and creating *ALL*
its output itself - this includes creating any directories which
are needed for its representation of the code. The user should not
need to work this out in advance and provide them.

2) With source and class files intermixed, packing up the source or
creating a Jar becomes a major headache. Surely the output direct
-ories should remain _pure_, containing only those files which form
the package?

3) This scheme pre-supposes that Java compilers will always use direct-
ories to model their package hierarchy - which might not always be
the case.

I can think of a handful of other reasons why I think this scheme is
inferior, but I think I've already made my point...! :-) So, the
question is... Is this *really* the 'standard way' (or conventional
way) of holding Java source - or are all these coders just ignorant
of the -d switch ???
-FISH- ><>
Jul 17 '05 #1
9 5300
I think this may be a difference in JDKs. I prefer that the package
source be in all one place and the JDK build the tree as it compiles.

-Misk

FISH wrote:
Ever have one of those days when you're not sure if it's you who's gone
mad, or the rest of the world?

I have an Open Source project on SourceForge for communication with YSMG
- Yahoo's IM protocol. I keep the project source in three directories,
based upon the code's function: one for the network API code itself, one
for the support APIs (basic chat spam filtering, Swing models, rich text
decoders, etc), and one for the test client built using the network API.

When I compile I use the -d option on Sun's SDK... the compiler builds
the necessary directory tree (if not already there from a previous build)
and places the class files into it.

One or two users have complained that the source is in the wrong direct-
ories and it won't compile. One guy helpfully rearranged the source tree
and mailed me a zip file - telling me this is the 'standard way' to store
Java source.

What they do is they build the package directory tree by hand, place
their .java files into the appropriate directories, and then just
"javac *.java" in each directory of the tree. The result is that, in
the absense of a specified output directory, the class files end up
right next to the source files - but this works because the source
code directory structure has been created to mirror the package names.

This isn't the first time I've seen this done - I've noted a programmer
where I work does the same thing! And although it works, to me it is
less than ideal. I have a hard time accepting that this is the 'standard
way', for several reasons:

1) The compiler should be responsible for organising and creating *ALL*
its output itself - this includes creating any directories which
are needed for its representation of the code. The user should not
need to work this out in advance and provide them.

2) With source and class files intermixed, packing up the source or
creating a Jar becomes a major headache. Surely the output direct
-ories should remain _pure_, containing only those files which form
the package?

3) This scheme pre-supposes that Java compilers will always use direct-
ories to model their package hierarchy - which might not always be
the case.

I can think of a handful of other reasons why I think this scheme is
inferior, but I think I've already made my point...! :-) So, the
question is... Is this *really* the 'standard way' (or conventional
way) of holding Java source - or are all these coders just ignorant
of the -d switch ???
-FISH- ><>

--
================================================== ======================
Missaka Wijekoon (a.k.a. Misk) mw*******@RemoveThis.villageEdocs.com
Sr. Software Engineer http://www.villageEdocs.com
VillageEdocs
================================================== ======================
Jul 17 '05 #2
I think this may be a difference in JDKs. I prefer that the package
source be in all one place and the JDK build the tree as it compiles.

-Misk

FISH wrote:
Ever have one of those days when you're not sure if it's you who's gone
mad, or the rest of the world?

I have an Open Source project on SourceForge for communication with YSMG
- Yahoo's IM protocol. I keep the project source in three directories,
based upon the code's function: one for the network API code itself, one
for the support APIs (basic chat spam filtering, Swing models, rich text
decoders, etc), and one for the test client built using the network API.

When I compile I use the -d option on Sun's SDK... the compiler builds
the necessary directory tree (if not already there from a previous build)
and places the class files into it.

One or two users have complained that the source is in the wrong direct-
ories and it won't compile. One guy helpfully rearranged the source tree
and mailed me a zip file - telling me this is the 'standard way' to store
Java source.

What they do is they build the package directory tree by hand, place
their .java files into the appropriate directories, and then just
"javac *.java" in each directory of the tree. The result is that, in
the absense of a specified output directory, the class files end up
right next to the source files - but this works because the source
code directory structure has been created to mirror the package names.

This isn't the first time I've seen this done - I've noted a programmer
where I work does the same thing! And although it works, to me it is
less than ideal. I have a hard time accepting that this is the 'standard
way', for several reasons:

1) The compiler should be responsible for organising and creating *ALL*
its output itself - this includes creating any directories which
are needed for its representation of the code. The user should not
need to work this out in advance and provide them.

2) With source and class files intermixed, packing up the source or
creating a Jar becomes a major headache. Surely the output direct
-ories should remain _pure_, containing only those files which form
the package?

3) This scheme pre-supposes that Java compilers will always use direct-
ories to model their package hierarchy - which might not always be
the case.

I can think of a handful of other reasons why I think this scheme is
inferior, but I think I've already made my point...! :-) So, the
question is... Is this *really* the 'standard way' (or conventional
way) of holding Java source - or are all these coders just ignorant
of the -d switch ???
-FISH- ><>

--
================================================== ======================
Missaka Wijekoon (a.k.a. Misk) mw*******@RemoveThis.villageEdocs.com
Sr. Software Engineer http://www.villageEdocs.com
VillageEdocs
================================================== ======================
Jul 17 '05 #3
FISH wrote:

What they do is they build the package directory tree by hand, place
their .java files into the appropriate directories, and then just
"javac *.java" in each directory of the tree. The result is that, in
the absense of a specified output directory, the class files end up
right next to the source files - but this works because the source
code directory structure has been created to mirror the package names.

This isn't the first time I've seen this done - I've noted a programmer
where I work does the same thing! And although it works, to me it is
less than ideal. I have a hard time accepting that this is the 'standard
way', for several reasons:

1) The compiler should be responsible for organising and creating *ALL*
its output itself - this includes creating any directories which
are needed for its representation of the code. The user should not
need to work this out in advance and provide them.

2) With source and class files intermixed, packing up the source or
creating a Jar becomes a major headache. Surely the output direct
-ories should remain _pure_, containing only those files which form
the package?

3) This scheme pre-supposes that Java compilers will always use direct-
ories to model their package hierarchy - which might not always be
the case.

I can think of a handful of other reasons why I think this scheme is
inferior, but I think I've already made my point...! :-) So, the
question is... Is this *really* the 'standard way' (or conventional
way) of holding Java source - or are all these coders just ignorant
of the -d switch ???


Fish,

I think to say that organizing the source code in this manner is
standard. Many Java IDEs expect the code to be this way and some
compilers will even emit warnings or errors if it is not.

However, it is not as bad as it seems. You can still use the -d option
even when the source code is arranged this way. So you can still
separate the source code and the class files easily.

Let me address your concerns:

1) The compiler does create the output; the source code and the
directories it is contained in are input.
2) One can still use the -d flag to separate source and class files.
3) I was going to dismiss this concern as silly, but the JLS does
explicitly mention using a database to store classes, so that would have
been wrong of me. However, I doubt this is a serious concern for the
near future.

Finally, let me suggest that you try out ANT. ANT provides a way of
easily specifying how to build your code. It can run the compiler and
jar the files. As an added bonus you can distribute the build script
and everyone working on the code will be able to build it in the same way.

Good luck with your future endeavors,

Ray


Jul 17 '05 #4
FISH wrote:

What they do is they build the package directory tree by hand, place
their .java files into the appropriate directories, and then just
"javac *.java" in each directory of the tree. The result is that, in
the absense of a specified output directory, the class files end up
right next to the source files - but this works because the source
code directory structure has been created to mirror the package names.

This isn't the first time I've seen this done - I've noted a programmer
where I work does the same thing! And although it works, to me it is
less than ideal. I have a hard time accepting that this is the 'standard
way', for several reasons:

1) The compiler should be responsible for organising and creating *ALL*
its output itself - this includes creating any directories which
are needed for its representation of the code. The user should not
need to work this out in advance and provide them.

2) With source and class files intermixed, packing up the source or
creating a Jar becomes a major headache. Surely the output direct
-ories should remain _pure_, containing only those files which form
the package?

3) This scheme pre-supposes that Java compilers will always use direct-
ories to model their package hierarchy - which might not always be
the case.

I can think of a handful of other reasons why I think this scheme is
inferior, but I think I've already made my point...! :-) So, the
question is... Is this *really* the 'standard way' (or conventional
way) of holding Java source - or are all these coders just ignorant
of the -d switch ???


Fish,

I think to say that organizing the source code in this manner is
standard. Many Java IDEs expect the code to be this way and some
compilers will even emit warnings or errors if it is not.

However, it is not as bad as it seems. You can still use the -d option
even when the source code is arranged this way. So you can still
separate the source code and the class files easily.

Let me address your concerns:

1) The compiler does create the output; the source code and the
directories it is contained in are input.
2) One can still use the -d flag to separate source and class files.
3) I was going to dismiss this concern as silly, but the JLS does
explicitly mention using a database to store classes, so that would have
been wrong of me. However, I doubt this is a serious concern for the
near future.

Finally, let me suggest that you try out ANT. ANT provides a way of
easily specifying how to build your code. It can run the compiler and
jar the files. As an added bonus you can distribute the build script
and everyone working on the code will be able to build it in the same way.

Good luck with your future endeavors,

Ray


Jul 17 '05 #5
Raymond DeCampo <rd******@spam-I-am-not.twcny.rr.com> wrote in message news:<qj*******************@twister.nyroc.rr.com>. ..
Let me address your concerns:

1) The compiler does create the output; the source code and the
directories it is contained in are input.
Ah yes, but in Java the package 'hierarchy' is part of the output, so
surely it is more correct that the directories should be constructed
by the compiler - by referencing the source - than created by the
programmer by hand...?

2) One can still use the -d flag to separate source and class files.
Which begs the question, why not use -d all the time? (Then you never
get source and binary intermixed in the same directories!)

Hmmmm... :-)

3) I was going to dismiss this concern as silly, but the JLS does
explicitly mention using a database to store classes, so that would have
been wrong of me. However, I doubt this is a serious concern for the
near future.
I think this pretty much answers the question for me. The fact that
it 'works for now' would suggest to me that this union (in the C
sense of the word) of source and output directories it is not a
desirable way to structure code - and obviously not a 'standard way'.

It works because the compiler will output to the same directory as
the source, if not directed. I'm not sure if this default behaviour
can be guaranteed in future, or on all compilers - so I'd rather
avoid it.

Finally, let me suggest that you try out ANT. ANT provides a way of
easily specifying how to build your code. It can run the compiler and
jar the files. As an added bonus you can distribute the build script
and everyone working on the code will be able to build it in the same way.


I already use Ant, thanks :-) In fact the package I mentioned is
actually used in one of the many extensions to Ant, called ImTask.
Thanks for your input, but I think I'll stick to packaging the source
in a way that makes sense to the project, and leave the compiler to
figure out how it wants to implementent the package 'hierarchy' - it
probably has a better idea than I do :-)

Thanks,

-FISH- ><>
Jul 17 '05 #6
Raymond DeCampo <rd******@spam-I-am-not.twcny.rr.com> wrote in message news:<qj*******************@twister.nyroc.rr.com>. ..
Let me address your concerns:

1) The compiler does create the output; the source code and the
directories it is contained in are input.
Ah yes, but in Java the package 'hierarchy' is part of the output, so
surely it is more correct that the directories should be constructed
by the compiler - by referencing the source - than created by the
programmer by hand...?

2) One can still use the -d flag to separate source and class files.
Which begs the question, why not use -d all the time? (Then you never
get source and binary intermixed in the same directories!)

Hmmmm... :-)

3) I was going to dismiss this concern as silly, but the JLS does
explicitly mention using a database to store classes, so that would have
been wrong of me. However, I doubt this is a serious concern for the
near future.
I think this pretty much answers the question for me. The fact that
it 'works for now' would suggest to me that this union (in the C
sense of the word) of source and output directories it is not a
desirable way to structure code - and obviously not a 'standard way'.

It works because the compiler will output to the same directory as
the source, if not directed. I'm not sure if this default behaviour
can be guaranteed in future, or on all compilers - so I'd rather
avoid it.

Finally, let me suggest that you try out ANT. ANT provides a way of
easily specifying how to build your code. It can run the compiler and
jar the files. As an added bonus you can distribute the build script
and everyone working on the code will be able to build it in the same way.


I already use Ant, thanks :-) In fact the package I mentioned is
actually used in one of the many extensions to Ant, called ImTask.
Thanks for your input, but I think I'll stick to packaging the source
in a way that makes sense to the project, and leave the compiler to
figure out how it wants to implementent the package 'hierarchy' - it
probably has a better idea than I do :-)

Thanks,

-FISH- ><>
Jul 17 '05 #7
FISH wrote:
Raymond DeCampo <rd******@spam-I-am-not.twcny.rr.com> wrote in message news:<qj*******************@twister.nyroc.rr.com>. ..
Let me address your concerns:

1) The compiler does create the output; the source code and the
directories it is contained in are input.

Ah yes, but in Java the package 'hierarchy' is part of the output, so
surely it is more correct that the directories should be constructed
by the compiler - by referencing the source - than created by the
programmer by hand...?

I do not understand your point of view. The package structure is NOT
dictated by the compiler. The programmer dictates to the compiler what
the package structure should be via the "package" directive. So the
package hierarchy is in fact totally controlled by the programmer and
the source.

2) One can still use the -d flag to separate source and class files.

Which begs the question, why not use -d all the time? (Then you never
get source and binary intermixed in the same directories!)


As a matter of fact, I always do. I think most tools also support and
encourage this separation. It has nothing to do with the question of
how one should organize one's source code however.

Hmmmm... :-)
3) I was going to dismiss this concern as silly, but the JLS does
explicitly mention using a database to store classes, so that would have
been wrong of me. However, I doubt this is a serious concern for the
near future.

I think this pretty much answers the question for me. The fact that
it 'works for now' would suggest to me that this union (in the C
sense of the word) of source and output directories it is not a
desirable way to structure code - and obviously not a 'standard way'.

It works because the compiler will output to the same directory as
the source, if not directed. I'm not sure if this default behaviour
can be guaranteed in future, or on all compilers - so I'd rather
avoid it.


I'm not sure what "it works" refers to. We agree that the source and
class files should be separate. I am advocating structuring the source
code based on the package hierarchy; you are advocating structuring the
source code in an arbitrary manner based on logical groupings of
functionality. As far as I can see, my method is a subcase of yours so
I certainly hope you think it works!


Finally, let me suggest that you try out ANT. ANT provides a way of
easily specifying how to build your code. It can run the compiler and
jar the files. As an added bonus you can distribute the build script
and everyone working on the code will be able to build it in the same way.

I already use Ant, thanks :-) In fact the package I mentioned is
actually used in one of the many extensions to Ant, called ImTask.


In that case, let me say thanks for adding to the wealth of open source
tools.

Thanks for your input, but I think I'll stick to packaging the source
in a way that makes sense to the project, and leave the compiler to
figure out how it wants to implementent the package 'hierarchy' - it
probably has a better idea than I do :-)


I hope you take this discussion in the spirit of which it is given --
simply an academic discussion about source code organization. I haven't
meant to insult you in any way nor do I really care how you organize
your source code...it was just a fun topic. After all, the real measure
of code is how it runs, not what directory it lives in.

Ray
Jul 17 '05 #8
Raymond DeCampo <rd******@spam-I-am-not.twcny.rr.com> wrote in message news:<3P*******************@twister.nyroc.rr.com>. ..
FISH wrote:
Raymond DeCampo <rd******@spam-I-am-not.twcny.rr.com> wrote in message news:<qj*******************@twister.nyroc.rr.com>. ..
[snipped...] Which begs the question, why not use -d all the time? (Then you never
get source and binary intermixed in the same directories!)

As a matter of fact, I always do. I think most tools also support and
encourage this separation. It has nothing to do with the question of
how one should organize one's source code however.


Well the question I asked was about programmers who don't use the -d
switch. They visit each source code directory and run "javac *.java"
in it... which works because the compiler defaults to outputing the
class files into the same directory as the source when not directed
otherwise. (It's pretty much the same way one would build code from
C source in multiple directories, or other compiled languages.)

At first I thought this was just a few novice programmers who didn't
understand that the directory structure was just an implementation
detail - it was the way that the original compilers choose to render
their namespace... and indeed it would be just as valid for the
compiler to dispense with the directories altogether and build their
code straight into a Jar file, or even into a database...

Then I started getting a few emails from coders who were clearly
not novices, who said that Java source code is supposed to mirror
exactly the package structure - that this is a standard way of
doing things. All along I had assumed that (physical) source
code directory structure could be independent of the actual (and
logical) namespace structure used within the code --- now a few
coders where telling me this was wrong, and that the 'proper' way
of doing things was to have them match exactly.

I'm not sure what "it works" refers to. We agree that the source and
class files should be separate. I am advocating structuring the source
code based on the package hierarchy; you are advocating structuring the
source code in an arbitrary manner based on logical groupings of
functionality. As far as I can see, my method is a subcase of yours so
I certainly hope you think it works!
Aha - I think I see where we are now. We actually agree, except on a
small point which is just a matter of taste,

The point I was originally asking about was whether the source code
directory structure *must* match exactly the package 'hierarchy' -
and the class files should be built into the same directories as the
source files they came from. What you are saying, as I understand
it, is that the two things should be separate, and it is a matter of
taste (or practicality) as to whether the source layout should match
the package hierarchy.

On that point I whole-heartedly agree.
[snipped...] I hope you take this discussion in the spirit of which it is given --
simply an academic discussion about source code organization. I haven't
meant to insult you in any way nor do I really care how you organize
your source code...it was just a fun topic. After all, the real measure
of code is how it runs, not what directory it lives in.

Actually it was I who was worried that I may have insulted you! I
mean, here was me, asking advice on something - and then being
cheeky enough to start arguing-the-toss with those who choose to
reply. :-)

I think actually, when all the smoke has cleared, we agree. You
like to lay your source files out one way, I like to do it another.
That's exactly how it should be! But we agree that the layout of
the source files - no matter which way - should not be *mandated* by
the namespace 'hierarchy' ... these are two separate structures and
coders should be free to make them as similar or distant as they
want!

I think that, no matter which way you lay things out, you should
*always* use the -d option to build the classes into a clean and
independent structure. (Indeed I think it might be a good idea if
compilers started spitting out a warning if this option isn't set!)
I've added a README to my project's latest download to that effect.

Btw: if you are at all curious... http://jymsg9.sourceforge.net/

Thanks for an interesting discussion.

-FISH- ><>
Jul 17 '05 #9
jo*****@merseymail.com (FISH) wrote in message news:<db*************************@posting.google.c om>...

The point I was originally asking about was whether the source code
directory structure *must* match exactly the package 'hierarchy' -
and the class files should be built into the same directories as the
source files they came from.
Yes to the first question, and no to the second.
What you are saying, as I understand
it, is that the two things should be separate, and it is a matter of
taste (or practicality) as to whether the source layout should match
the package hierarchy.


As I understand it, the source files must (or should) be stored in a
directory structure that matches the package hierarchy, but that
doesn't mean that the class files go into the same directories along
with the source code. Rather, they go into an identically structured
directory tree that can be located anywhere you want. I generally have
a directory called "source" which contains the source code tree, and a
directory called "build" which contains the class file tree, and the
"source" and "build" directories live next to each other. I believe
that this is the "standard" way of doing things, if there is one.

At least, this is the way JBuilder (which I use at work) manages
projects by default, and the way that the example build file for Ant
(which I use at home) does things as well.
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Lem | last post by:
I get the error Exception in thread "main" java.lang.NoClassDefFoundError when I type java app2 in the command prompt. I've tried moving to the jre directory and typed java c:\app2\app2, but it...
4
by: Abdelhalim MIMOUNI | last post by:
hi, i'm new to java, and using sun last JDK, and i'm trying to understand how work this feature when we want to compile at command line ? i'm trying to set the classpath to the directory of the...
9
by: vegetax | last post by:
I was a java developer one year ago ,before i moved to python i realy liked it at the beggining, but i got very disapointed lately since my previus two python proyects where relatively big,and...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.