I usually do my java development inside an IDE. But I need to compile
my code from the Windows command line. I have two packages:
ProjectName\src\com\CodeSupplier\CodeFolder, and
ProjectName\src\MyProject
The program uses java files from both packages.
How do I compile this? When I try, I just get errors, because javac
doesn't know where the other package is. (From Netbeans, this works.)
Thanks!
Rhino - 04 May 2006 20:50 GMT
>I usually do my java development inside an IDE. But I need to compile
> my code from the Windows command line. I have two packages:
[quoted text clipped - 6 lines]
> How do I compile this? When I try, I just get errors, because javac
> doesn't know where the other package is. (From Netbeans, this works.)
I don't think I ever did this myself but I recall reading this question in
the old Java FAQ. I'm certain that the answer said you had to compile them
both at the same time. I think the command line needs to look like this; I'm
not certain this is 100% right but it should be pretty close:
javac my\com\foo.java my\othercom\bar.java
I also seem to recall that if the source files are in the same directory,
you can do a:
javac *.java
and all source files in the directory will get compiled. Again, I'm not
certain of the exact syntax but I think it is pretty close to what I have
given.
--
Rhino
Carl - 04 May 2006 22:12 GMT
> I usually do my java development inside an IDE. But I need to compile
> my code from the Windows command line. I have two packages:
[quoted text clipped - 8 lines]
>
> Thanks!
Hello,
You are able to tell javac where to find you source files using the
-sourcepath flag. From the docs (
http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/javac.html ):
"-sourcepath sourcepath Specify the source code path to search for
class or interface definitions. As with the user class path, source
path entries are separated by colons (:) and can be directories, JAR
archives, or ZIP archives. If packages are used, the local path name
within the directory or archive must reflect the package name.
Note that classes found through the classpath are subject to
automatic recompilation if their sources are found."
I hope that helps,
Carl.
Knute Johnson - 05 May 2006 06:39 GMT
> I usually do my java development inside an IDE. But I need to compile
> my code from the Windows command line. I have two packages:
[quoted text clipped - 8 lines]
>
> Thanks!
The package names of your classes need to match the directory structure.
Also you need to be in a directory above the top of your package
directory to compile the files. So if you have a class:
/com/knutejohnson/programs/MyProgram.java
and a class:
/com/knutejohnson/components/MyComponent.java
you need to be in the / directory and enter:
javac com/knutejohnson/programs/MyProgram.java
This will compile both files and then you can run the program with:
java com.knutejohnson.programs.MyProgram
This is one of the most difficult subjects to explain and understand
when you first start using packages. It is only exceeded by CLASSPATH.
Using jar files with packages is done similarly.

Signature
Knute Johnson
email s/nospam/knute/
ramakrishna - 05 May 2006 08:20 GMT
You can do this by using -sourcepath directive in javac
But I need clarification regarding this one
javac -sourcepath com/*.java:com.thing/*.java:com.thing.network/*.java
it will work nice
but in my current project i have some many folders and i need to
complie the all java file.
Is there any option regarding this one to compile all the files
including subdirectores.
Thank u
TechBookReport - 05 May 2006 11:44 GMT
> I usually do my java development inside an IDE. But I need to compile
> my code from the Windows command line. I have two packages:
[quoted text clipped - 8 lines]
>
> Thanks!
Have you considered using a build tool like apache ant? If you're going
to be doing a lot of this then the extra effort to define the build
configuration will be worth the pay off.

Signature
TechBookReport Java http://www.techbookreport.com/JavaIndex.html