compiling multiple packages from the command line?

  • Thread starter nooneinparticular314159
  • Start date
N

nooneinparticular314159

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!
 
R

Rhino

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.)
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.
 
C

Carl

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!

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.
 
K

Knute Johnson

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!

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.
 
R

ramakrishna

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
 
T

TechBookReport

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!
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top