Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Java commandline -cp parameter  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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: 39286
745
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!