File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Running Java from jar file! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running Java from jar file!" Watch "Running Java from jar file!" New topic
Author

Running Java from jar file!

resh singh
Greenhorn

Joined: Aug 14, 2006
Posts: 9
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Aug 14, 2006
Posts: 9
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Aug 14, 2006
Posts: 9
It works after making the change to relative path.

Thank You so much!

-Resh
 
 
subject: Running Java from jar file!