Forums Register Login

Ant javac task and subdirectories

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
What package was the original SomeClass in? Ant determines which directory to place the class file by the package that it is in.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
Squanch that. And squanch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3993 times.
Similar Threads
help in setting classpath in ant
javac and directory structures
urgent help please (creating jar file using ant)
Fallen at the first hurdle!
Head First Servlets and JSp problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:49:35.