aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 3971
    
  17

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: 3971
    
  17

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: 3971
    
  17

Your quite welcome. These are easy mistakes to make, so don't feel bad at all. Just keep chugging :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Importing packages from a .jar
 
Similar Threads
System.console
K&B SCJP Book - Chapter 10
EARs, WARs, classpaths, and manifests
.jar file in classpath
Eclipse + Tomcat + JSP's on the Mac