aspose file tools*
The moose likes Beginning Java and the fly likes compiling java in command line with jar dependency and packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compiling java in command line with jar dependency and packages" Watch "compiling java in command line with jar dependency and packages" New topic
Author

compiling java in command line with jar dependency and packages

christine clarin
Ranch Hand

Joined: Feb 05, 2005
Posts: 106
Hello, i'm trying to compile my java file through the command line, but i have lots of packages and one jar file in which my code is dependent. how do i do this? here is a sample hierarchy of my packages. (I'm doing this in Mandriva)

/home/user/Documents

-- Folder1 //note: these packages contain only the .classes of the codes
- packageA
- packageB
- packageC
-- Folder2
- codeToCompile.java
-- jar file

how do i compile this? thanks! I have no idea how to use javac -cp for multiple classpaths. thanks! any help would be really great!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I assume you are using Unix. In Folder2 :
javac -cp /home/user/Documents/Folder1:/home/user/Documents/jarfile.jar codeToCompile.java

Make sure you have all the correct imports in your codeToCompile.java.
import packageA.*;
import packageB.*;
import packageC.*;
...


[My Blog]
All roads lead to JavaRanch
christine clarin
Ranch Hand

Joined: Feb 05, 2005
Posts: 106
hi, i already tried doing this before, but it doesn't work. these codes are actually made with eclipse, that's why it's quite easy working with packages. but now that i need to use the command line for it, i'm having some difficulties =( you also have to know that some of the class files in Folder1 are files from the jar file with some added methods. I'm guessing that the files in the jar file are overriding these new codes from folder1 that's why they're not recognized? Do you think that's it? thanks!
Sidd Kulk
Ranch Hand

Joined: Feb 20, 2007
Posts: 152
The jar files have internal packages too, make sure that you import them as well. If you use windows, you can set the environment variables. you can also externally set the classpath in command promt, using the command

set classpath=%classpath%;<path of your jars,classes etc.>

hope it helps

Njoy!!
Sid
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compiling java in command line with jar dependency and packages