This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Specify classpath when run class in jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Specify classpath when run class in jar file" Watch "Specify classpath when run class in jar file" New topic
Author

Specify classpath when run class in jar file

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
I have application packaged in jar file and I run my class using:

> java �jar myjar.jar

How do I specify a additional classpath at run time? This command would not work:

> java �cp myclasspath �jar myjar.jar


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
I use a classpath as follows...

java -classpath c:\mypath\myjar.jar myPackage.myClassFile

(where myClassFile has the main method)

Does that help you out?
Cheers,
Rachel
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Thanks.
In my case the class is in jar file and the classpath would not work. One can put the "Class-path: xxx" in the manifest but I am wondering if there is a way to specify it at run time.
Regards
[ October 11, 2004: Message edited by: Bruce Jin ]
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
It doesn't sound promising.

Clip from
java tools documentation


-jar
...
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

untestet:

(without the -jar option, and explicitly setting the Main-Class.)


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Specify classpath when run class in jar file
 
Similar Threads
question reg jar file
Lost with JAR files and packages
K&B doubt regarding question in Development chapter
Question No. 11- Chapter 10 K&B book SCJP 1.6 - Doubt on Answer
jar file