Re: Running java programs from class files
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Aug 2006 08:29:45 -0700
Babu Kalakrishnan wrote:
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
I did try that and it does work just fine. I think you are correct that you can't do what I was trying to do. See Nigel's post below.
Thanks very much Babu.
--
Knute Johnson
email s/nospam/knute/
.
- 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
- Re: Running java programs from class files
- From: Babu Kalakrishnan
- Running java programs from class files
- Prev by Date: Re: Running java programs from class files
- Next by Date: Form submission Encoding Problem - saving Japanese text to the database
- Previous by thread: Re: Running java programs from class files
- Next by thread: Re: Running java programs from class files
- Index(es):
Relevant Pages
|