Re: Running java programs from class files
- From: Babu Kalakrishnan <bkk.ngroup@xxxxxxxxx>
- Date: Thu, 31 Aug 2006 17:27:51 +0530
Knute Johnson wrote:
So now that you solved that one, show me how to use a jar library on the command line when I run a java program. I can make it compile but I can't make it run. I can get it to work if I put the jar file in the Class-Path: line in the manifest and put the jar file in the same directory as the program jar file but not from the command line.
Test is my slightly modified class that calls a static method in lib.Lib. The Lib class has been compiled and put into a jar file, lib.jar in the /lib directory. I then compile Test.java from the /test directory and run the .class file with no problems. You will see that the lib.Lib class can't be found once I jar it.
I don't think it is possible to achieve that if you're using -jar option of java. Once the -jar option is specified, whatever you specify as a -classpath or -cp option is essentially ignored, and the effective user classpath of the JVM becomes the specified jar file and the jars specified in that jar's manifest.
An alternative would be to not use the -jar option, but to run it as :
java -cp /path_to_lib_jar/lib.jar:/path_to_test_jar/test.jar test.Test
(i.e by explicitly specifying the main class to invoke, and specifying all the jar files in the classpath option)
BK
.
- Follow-Ups:
- Re: Running java programs from class files
- From: Knute Johnson
- Re: Running java programs from class files
- References:
- Running java programs from class files
- From: mark13 . pl
- Re: Running java programs from class files
- From: Knute Johnson
- Re: Running java programs from class files
- From: Babu Kalakrishnan
- Re: Running java programs from class files
- From: Knute Johnson
- Re: Running java programs from class files
- From: Oliver Wong
- Re: Running java programs from class files
- From: Knute Johnson
- Re: Running java programs from class files
- From: Babu Kalakrishnan
- Re: Running java programs from class files
- From: Knute Johnson
- Re: Running java programs from class files
- From: Babu Kalakrishnan
- Re: Running java programs from class files
- From: Knute Johnson
- Running java programs from class files
- Prev by Date: Re: Unescaping Unicode code points in a Java string
- Next by Date: Re: workaround to suspend the session object
- Previous by thread: Re: Running java programs from class files
- Next by thread: Re: Running java programs from class files
- Index(es):
Relevant Pages
|