Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Java from jar file!

 
resh singh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a standalone java program developed in eclipse, that connects to weblogic server and perform some actions. It works completely fine from eclipse, however I have to get this running on other non developer machine without any eclipse installed and configured.

I tried to do following and it failed.

I exported the source and class in jar file using eclipse export to jar file feature. Then edited the Manifest.mf file to include required jar file in class-path.

Manifest.mf:

Manifest-Version: 1.0
Main-Class: com.dweb.cms.utils.PublishUtil
Class-Path: C:\StatusImport\vgn-appsvcs-cma.jar

Then ran following command and got error below.

C:\StatusImport>java -jar publishUtil.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/dweb/cms/utils/Pu
blishUtil
Caused by: java.lang.ClassNotFoundException: com.dweb.cms.utils.PublishUtil
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com.dweb.cms.utils.PublishUtil. Program will exit
.

Thanks,
Reshma
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's just saying the obvious, that the class com.dweb.cms.utils.PublishUtil isn't in the jar. Looking at the manifest doesn't help to figure out why it isn't.

(By the way, the entries in the Class-Path line are supposed to be relative to the executable jar. I don't think that absolute file paths will work there but I could be wrong.)
 
resh singh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
com.dweb.cms.utils.PublishUtil is present in the publishUtil.jar file. About the absolute path it works fine, If I change it to relative It complains about classNotfoundException for the classes from the class-path jar.

Please suggest any other way to achieve the same thing.

Thanks,
Reshma
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
resh singh wrote:com.dweb.cms.utils.PublishUtil is present in the publishUtil.jar file.


The error message says it isn't. It's usually a good idea to believe error messages. Simply denying their correctness never leads to solving the underlying problem.

As for the full versus relative path question... I would do it like this:

which says that the vgn-appsvcs-cma.jar file will be in the same directory as the executable jar file. Then put the two files in the same directory.
 
resh singh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works after making the change to relative path.

Thank You so much!

-Resh
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic