• 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

Java commandline -cp parameter

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a directory c:\lib and it has 20 jar files in it. I want to run a class
from one of those jar files, what is the best way to do this from the java
commandline?


java -cp c:\lib <name of class> did not work.

Please tell me I don't have to enumerate every single jar file in that directory.

Using Java 6.0.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Todd Baxter:
I have a directory c:\lib and it has 20 jar files in it. I want to run a class from one of those jar files,


If the class only needs one jar, you only need to have that jar in the classpath. If all 20 jars are dependencies, you do need to enumerate them.
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the class is in a jar file the class path needs to point to that specific jar.

java -cp somedirectory\abc.jar
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As it's Java 6 you are using
java -cp c:\lib\* <name of class>
should work.

Note 1 - this is a new feature (since Java 5 I think). It won't work for earlier versions.
Note 2 - * does not have it's usual meaning of match all files - it only matches jar files. *.jar doesn't work - it must be just *

See the 'Understanding class path wildcards' section of this for full details.
[ September 19, 2008: Message edited by: Joanne Neal ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic