• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using a jar in classpath on command line

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

i am try to use a jar in the classpath on the command line and
it doesn't work. I have tried :
java -classpath testlib.jar -jar test.jar
where testlib.jar is a library jar needed to execute test.jar and test.jar
is a jar with a Main class described in its manifest.
Of course, both testlib.jar and test.jar are in the current directory.

On the other hand, putting testlib.jar in the ext/ directory inside the jre
and typing "java -jar test.jar" works well.

I really don't see why this doesn't work.
If any of you have a clue, let me know.

Gilles



Thanks for your help
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't work because it doesn't work.

When you use the "-jar" switch, the "-classpath" switch and the CLASSPATH environment variable are ignored. Executable jars are assumed to be self-contained.

Instead of saying

java -classpath X.jar -jar Y.jar

use something like

java -classpath X.jar;Y.jar com.something.MainClassFromYDotJar
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To add to what Ernest said:

The "-jar" switch is used to run executable JAR files. An executable JAR file contains a manifest file in which the main class and the classpath is specified. With the "-jar" switch, the -cp and -classpath options are ignored, and the classpath specified in the manifest file is used instead.

The Java Tutorial - Packaging Programs in JAR Files
 
Gilles Marceau
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much guys.

Gilles
 
reply
    Bookmark Topic Watch Topic
  • New Topic