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

From: Raymond DeCampo (rdecampo_at_spam-I-am-not.twcny.rr.com)
Date: 01/25/04


Date: Sun, 25 Jan 2004 03:00:38 GMT

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



Relevant Pages

  • Q: Java source and directory structure - standard way ?
    ... When I compile I use the -d option on Sun's SDK... ... and places the class files into it. ... Java source. ... code directory structure has been created to mirror the package names. ...
    (comp.lang.java)
  • Re: JavaC compilation error: . expected
    ... We have a set of pre-compiled .class files that sit on a client and ... These supporting .class ... under a package, as defined in their .java, but physically--on the ...
    (comp.lang.java.programmer)
  • Re: JavaC compilation error: . expected
    ... We have a set of pre-compiled .class files that sit on a client and ... files are generated by that program itself, and we pull reference and ... under a package, as defined in their .java, but physically--on the ...
    (comp.lang.java.programmer)
  • Re: java.lang.SecurityException: Prohibited package name: java
    ... in the 'java' package - so it looked as if you were trying ... Indeed using "javap Dropper" I get: ... Moving the class files into a directory called Dropper solved the problem. ...
    (comp.lang.java.programmer)
  • building java rpm
    ... I am trying to build a java rpm based on the nosrc.rpm from jpackage.org ... chmod -R u+w bin CHANGES COPYRIGHT javaws lib LICENSE man plugin ... This package contains source files for %. ...
    (Fedora)