• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java commandline -cp parameter  RSS feed

 
Todd Baxter
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
546
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.
 
Gamini Sirisena
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
 
Joanne Neal
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!