Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > "java -jar" vs "java -cp" question

Reply
Thread Tools

"java -jar" vs "java -cp" question

 
 
Markus Dehmann
Guest
Posts: n/a
 
      09-28-2005
I have my classes with the main method in main.jar, and an external
library in external.jar.

Now, I can start my application with:
java -cp main.jar:external.jar MainClass

Fine, but the following command does *not* work:
java -cp external.jar -jar main.jar MainClass

It doesn't find the classes in external.jar. Why not??

Thanks!
Markus
 
Reply With Quote
 
 
 
 
hinduu@gmail.com
Guest
Posts: n/a
 
      09-28-2005
Hi Markus

Here is the statement about -jar option in the java docs

-jar Executes a program encapsulated in a JAR archive. The
first argument is the name of a JAR file instead of a
startup class name.
In order for this option to work, the manifest of the
JAR file must contain a line of the form Main-
Class:classname. Here, classname identifies the class
having the public static void main(String[] args)
method that serves as your application's starting
point. See the Jar tool reference page and the Jar
trail of the Java Tutorial for information about work-
ing with Jar files and Jar-file manifests. When you
use this option, the JAR file is the source of all
user classes, and other user class path settings are
ignored.

The last sentence explains your scenario

-H


Markus Dehmann wrote:
> I have my classes with the main method in main.jar, and an external
> library in external.jar.
>
> Now, I can start my application with:
> java -cp main.jar:external.jar MainClass
>
> Fine, but the following command does *not* work:
> java -cp external.jar -jar main.jar MainClass
>
> It doesn't find the classes in external.jar. Why not??
>
> Thanks!
> Markus


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-28-2005
On Wed, 28 Sep 2005 00:30:03 -0400, Markus Dehmann
<(E-Mail Removed)> wrote or quoted :

>It doesn't find the classes in external.jar. Why not??


If you use a jar the classpath has to go INSIDE The jar. See
http://mindprod.com/jgloss/jar.html

The alternative is to put your aux jars in the ext directory.

See http://mindprod.com/jgloss/classpath.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments