Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compiling java in command line with jar dependency and packages

 
christine clarin
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.*;
...
 
christine clarin
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic