Working of jar files
posted 12 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hello Guys,
I created a project using Log4j framework in Netbeans on Windows, build and executed it using the generated jar file like below:
The contains of Manifest file within the Log4jTesting.jar is
Then I moved Log4jTesting.jar to another drive without the dependent libraries and tried to execute it but got following exception
So I set the classpath manually to "D:\myPro\Log4jTesting\dist" like below and tried executing again but still got the same exception
Can someone please tell me what I am doing wrong here ?
Thanks.
I created a project using Log4j framework in Netbeans on Windows, build and executed it using the generated jar file like below:
The contains of Manifest file within the Log4jTesting.jar is
Then I moved Log4jTesting.jar to another drive without the dependent libraries and tried to execute it but got following exception
So I set the classpath manually to "D:\myPro\Log4jTesting\dist" like below and tried executing again but still got the same exception
Can someone please tell me what I am doing wrong here ?
Thanks.
OCJP 6
posted 12 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The Class-Path manifest entry overrides the classpath environment variable
posted 12 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
When you moved the jar file to E drive without the dependency, it looks in the manifest file "classpath" for the dependency. You can try
java -cp <classpath on D> -jar <filename>
EDIT: remove the manifest class path and use the -cp flag to run.
java -cp <classpath on D> -jar <filename>
EDIT: remove the manifest class path and use the -cp flag to run.
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
posted 12 years ago
That is not going to work; the "-cp" option will be ignored when you use the "-jar" option. You can try running it without "-jar", but you'll have to specify the main class name on the command line. Put the jar file for the application and all dependency jar files on the classpath:
java -cp log4j.jar;myprogram.jar com.mypackage.MyProgram
Why did you do that? Your program obviously needs those other jar files. The dependencies are not compiled into your jar - you don't only need them when you compile the program, but also when you run the program.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
K. Tsang wrote:java -cp <classpath on D> -jar <filename>
That is not going to work; the "-cp" option will be ignored when you use the "-jar" option. You can try running it without "-jar", but you'll have to specify the main class name on the command line. Put the jar file for the application and all dependency jar files on the classpath:
java -cp log4j.jar;myprogram.jar com.mypackage.MyProgram
Khuzema Dharwala wrote:Then I moved Log4jTesting.jar to another drive without the dependent libraries
Why did you do that? Your program obviously needs those other jar files. The dependencies are not compiled into your jar - you don't only need them when you compile the program, but also when you run the program.
| I think I'll just lie down here for a second. And ponder this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |








