Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Compilation of java files  using javac -d option Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compilation of java files  using javac -d option" Watch "Compilation of java files  using javac -d option" New topic
Author

Compilation of java files using javac -d option

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hello,
If i have the following structure :


In pack2 directories there are some classes which depends on some classes in pack3 directories and vice-versa.

Now if i want to compile the src files using the following command pattern:
javac -d classes src

how to do it..
i have tried but it gives compilation errors.

And can somebody please let me know how Eclipse does it when it automatically compiles the code we are writing???


Thanks.


Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37890
    
  22
It is awkward; you have to start compiling the file which has no dependencies on any other files in your package structure. It is the one farthest from the main method, which can be difficult to guess.

The class with the main method in will be compiled last. Slightly easier to guess which one.

Don't know how the IDEs do it.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Its not that bad, if a dependent class is on the source path the javac will find it and compile it. That said, I use Windows mostly and I usually just write a script called compile and call that from the command line, I keep all my class names listed in separate text file:

compile.bat


\resources\sourceclasses.txt

[ April 19, 2007: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Thanks Garrett,


Its not that bad, if a dependent class is on the source path the javac will find it and compile it.


If you have any knowledge regarding how come this works please let me know i am very much curious to know about this.

Thanks
kiran kumar kondru
Greenhorn

Joined: Feb 21, 2007
Posts: 3
You can otherwise set the CLASSPATH to the correct directory i.e.

CLASSPATH=src;

probably your files in source are in good package structure.

How this works? Here it is

when you set the classpath to src, the javac or java uses them to find other classes. For this situation your file in pack2 will have the package statement as

package com.samples.java.pack2;

when this statement is encountered it checks whether a folder named "com" exists or not. for this it checks all the paths set in the classpath variable. since our classpath is set, it find com and it finds samples etc.


And Miles to go before I sleep<br />And Miles to go before I sleep
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compilation of java files using javac -d option
 
Similar Threads
Compiling java files in different packages with single javac command
packages and compailation
package problem
Package Problem
package trouble