Class file output location

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Jon Copperthite

Class file output location

Post by Jon Copperthite »

I would like to separate my source files from my class files in a mirror directory structure. How can I do that with Textpad?

example:
f:\dev\src\com\etc....

all class files would be compiled into these directories:
f:\dev\class\com\etc....

thanks.
Garrett Johnson

Re: Class file output location

Post by Garrett Johnson »

You can do that with parameters passed to the jdk:

The java documentation I refer to to answer this is located at:

http://java.sun.com/j2se/1.4/docs/toold ... ml#options


Assuming that you will always follow that directory structure you mentioned above, AND that you only have three package levels, i.e.:
"com.mycom.mypack",
you would need to use the following command line:

javac.exe -d ..\..\..\class FileName.java

This translates, for the default javac compiler supplied by TextPad, to:

Command: UNCHANGED
Parameters: -d ..\..\..\class $File
Initial folder: UNCHANGED

However, if you have multiple package levels, i.e.:
"com.mycom.mypack"
"com.mycom.mypack.mysubpack"
"com.mycom.mypack.myothersubpack"
Then you can't do this flexible solution. In that case, just write out the ABSOLUTE path after the -d parameter:

Command: UNCHANGED
Parameters: -d F:\dev\class\
Initial folder: UNCHANGED

Anyway, that should work with all but the oldest jdk's, which may not support this, though it'll work as far back as jdk 1.1.8.
Thanh

Re: Class file output location

Post by Thanh »

Garrett Johnson,

This works great, thanks for the answer. However, if I compile another source that depends on the classes in my package, it can't find them. For example, I have utils.java that is a class by itself and is compiled to com.asetech.slideshow. When I compile the next class that depends on utils.java, Textpad tells me that i can't find it. My folder structure is:

d:\slideshow\src\*.java
d:\slideshow\classes\com\asetech\slideshow\*.class

I'm using the compile option -d ..\classes $File. This works great. Just can't compile source relying on classes that went to the package folder.

Can you help?

Thanks.
A Trimeloni

Re: Class file output location

Post by A Trimeloni »

...if I compile another source that depends on the classes in my package, it can't find them. For example, I have utils.java that is a class by itself and is compiled to com.asetech.slideshow. When I compile the next class that depends on utils.java, Textpad tells me that i can't find it. My folder structure is:

d:\slideshow\src\*.java
d:\slideshow\classes\com\asetech\slideshow\*.class

I'm using the compile option -d ..\classes $File. This works great. Just can't compile source relying on classes that went to the package folder.

>>

The -d option takes care of you problem with changing the directory. If you are also worried about other files having trouble finding them, try adding -classpath afterwords as well. Then the compiler wll try down the classpath you specify when it looks for the files.

you should then have:

Command: UNCHANGED
Parameters: -d F:\dev\class\ -classpath f:\dev\class
Initial folder: UNCHANGED
Post Reply