File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant javac task and subdirectories Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant javac task and subdirectories" Watch "Ant javac task and subdirectories" New topic
Author

Ant javac task and subdirectories

Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi everybody,
How can I preserve the directory structure and store class files? This is what I want:
+source
|  build.xml
|  +com
|     +bge
|        +eCare
|           +staff
|              someClass.java
|              +ejb
|                 Staff.java
|                 StaffEJB.java
|                 StaffHome.java
+build
|  +com
|     +bge
|        +eCare
|           +staff
|              SomeClass.class
|              +ejb
|                 Staff.class
|                 StaffEJB.class
|                 StaffHome.class
Ideally, I want to compile all java files, moving the whole directory structure as a java files.
<property name="build" value="../build" />
<property name="source" value="./com/bge/eCare/staff" />
...
    <target name="compile" depends="prepare">
<javac srcdir="${source}" destdir="${build}" debug="on">
    <classpath refid="class.path" />
</javac>
    </target>
When I use above portion to compile, instead I get this:
+build
|  +com
|     +bge
|        +eCare
|           +staff
|              +ejb
|                 SomeClass.class
|                 Staff.class
|                 StaffEJB.class
|                 StaffHome.class
javac task look directories recursively when it is looking for a source file. But when it's generating class file, it just puts everything in one directory. The funny part(I think) is that it chooses "ejb" folder as the destination. Not "staff" folder. I deleted "build" directly manually, but still comes out like this.
Hmm... Why???
How can I redirect generated class files in a way I specified?
If you have any idea, please let me know.
Thanks in advance.
Shin Hashitani
[ March 03, 2002: Message edited by: Shin Hashitani ]

/*<br /> * Quants Inc.<br /> * Engineer<br /> *<br /> * Shin Hashitani<br /> * hashitani@quants.co.jp<br /> * <a href="http://www.quants.co.jp" target="_blank" rel="nofollow">www.quants.co.jp</a><br />*/
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
As the Ant documentation says:
The directory structure of the source tree should follow the package hierarchy.
if you aren't doing this then you should do your javac in two different pieces using excludes/includes. See http://jakarta.apache.org/ant/manual/CoreTasks/javac.html for more details.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi Thomas,
Oh, now I got it.
I thought "distdir" means the root of destination directory. I run in NetBeans and in separetely installed Ant from command line, and got the same result. I guess I have to follow your suggestion.
Thank you so much.

Shin Hashitani
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
I misunderstood something again.
I copied SomeClass.java, changed name, and put it in the same directory. Then, that copied file alone is generated under /build/com/bge/Staff directly. The original SomeClass was still created in /build/com/bge/Staff/ejb directory.
I found this really odd.
I copied one more, and again that compied file was generated in the proper directory.
I used a fake name as SomeClass.java. Which is in fact named InvalidInputException.java. I changed the name of this file to SomeClass.java (Literally). Then, it is properly generated in that directory, not "ejb" directory.
I guess the name InvalidInputException.java was conflicting with some other file. Or something. Actually I am still puzzled.
I realized the source of the problem,
but I am still not sure why.
Thomas,
do you have any idea why this happened?
If you know, please let me know.

Thank you
Shin Hashitani
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
What package was the original SomeClass in? Ant determines which directory to place the class file by the package that it is in.
Greg Brouelette
Ranch Hand

Joined: Jan 23, 2002
Posts: 144
The only time I've seen this happen is when the package name in the file didn't match the actual directory in which the file resides. So, if the file is physically in the a/b/c directory, but the package for this file is a/b/f then the class file will go into the a/b/f directory.


For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Thomas, Greg,
thank you for your posting.
I changed the name of "SomeClass.java" back to "InvalidInputException.java" one more time to see if I get an error.
Well,
now InvalidInputException.class is in the right place; not in "ejb" directory. I changed the name through NetBeans' "Rename" function, which changes class name, constructors and other things specific to a class name. It must be something wrong with one of those names. As Greg mentioned, maybe the package name was wrong. I thought I checked that, but it could be.
Anyway,
now I cannot make the error, so I think this is it.
I was worried that I could not use the Ant tool properly and it would affect the productivity, but now I feel better. Next time, I'll check things thoroughly.
Thank you again for your time.
Shin Hashitani
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant javac task and subdirectories