Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

compiling multiple packages from the command line?

Thread view: 
nooneinparticular314159@yahoo.com - 04 May 2006 20:27 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:

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.