Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Markus Dehmann - 28 Sep 2005 05:30 GMT
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
hinduu@gmail.com - 28 Sep 2005 06:24 GMT
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

> I have my classes with the main method in main.jar, and an external
> library in external.jar.
[quoted text clipped - 9 lines]
> Thanks!
> Markus
Roedy Green - 28 Sep 2005 06:28 GMT
>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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.