This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Importing packages from a .jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Importing packages from a .jar" Watch "Importing packages from a .jar" New topic
Author

Importing packages from a .jar

George C Nixon
Greenhorn

Joined: Oct 21, 2009
Posts: 3
Hi,

I'm having a lot of difficulty doing something fairly simple... I just want to import a package in one .java file from a .jar file that's in the same directory, but javac is giving me headaches. I can't find the right command in Windows command prompt to make this compile. I keep trying stuff like:

javac NameUser.java -classpath=.;Name.jar

And more complicated variants with full path names. No joy!

I'm sure this'll be an easy one, so thanks in advance

George
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

I haven't done things from the command line in a while, so I could be off, but I think you need to put the name of the .java file at the end of the command, and the options you want to use before it:

javac -classpath=.;Name.jar NameUser.java

You might also benefit from surrounding the classpath in quotes, not sure though

javac -classpath=".;Name.jar" NameUser.java

Steve
George C Nixon
Greenhorn

Joined: Oct 21, 2009
Posts: 3
Thanks for replying, Steve

I just tried this line (cut and pasted from my command line):

javac -classpath=".;Name.jar" NameUser.java

But I still get the messages:
javac: invalid flag: -classpath=.;Name.jar
Usage: javac <options> <source files>
use -help for a list of possible options

Any ideas?? G
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Okay, just ran it myself, get rid of the equal sign:

George C Nixon
Greenhorn

Joined: Oct 21, 2009
Posts: 3
Urgh, thanks! You stare at code long enough, and you stop seeing things like that!

I've got an error trying to run the program, but at least it seems to have compiled.

Thanks Steve! G
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Your quite welcome. These are easy mistakes to make, so don't feel bad at all. Just keep chugging :-)
 
Consider Paul's rocket mass heater.
 
subject: Importing packages from a .jar