• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Working of jar files

 
Ranch Hand
Posts: 75
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Class-Path manifest entry overrides the classpath environment variable
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic