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 Problems running 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 "Problems running jar file" Watch "Problems running jar file" New topic
Author

Problems running jar file

D Slevin
Greenhorn

Joined: Jul 29, 2009
Posts: 6
Hi,

I've created a jar file and when I double-click it within the folder in which it is created, it works fine. I added my own manifest file so that I could specify the main class to be run and the class path
for the various jars I've needed to include. When I copy the jar file to the Desktop and run it there, it runs but the images are missing and I cant use the other jar files that I need. Has anyone encountered this problem before?

Any help would be appreciated.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How did you define the classpath in the jar?
D Slevin
Greenhorn

Joined: Jul 29, 2009
Posts: 6
I defined it within the Manifest file (Manifest.txt) as follows:

Main-Class: Gui
Class-Path: extra-jar-files/PDFBox-0.7.3.jar extra-jar-files/some_other_jar.jar

I had to include a number of jar files and I defined them on separate lines preceded by a space. The extra-jar-files folder is located in the same folder as the class files.
It works if the jar is run in that folder, but if I try to run it on another folder it cant find the jar files or the images needed by the GUI.
D Slevin
Greenhorn

Joined: Jul 29, 2009
Posts: 6
It seems that the GUI is looking for the extra jar files in the path relative to the one that the jar is run in. Is there a way to create a jar file
so that it checks the folder extra-jar-files for those extra jars?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sure--use a path that resolves to where the jars are.
D Slevin
Greenhorn

Joined: Jul 29, 2009
Posts: 6
I do, but I need to be able to run the jar file on another computer and that's
what Im having trouble with.

Anyways, thanks for the help.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You don't when you move the jar file away from where the manifest says the jar files are...
 
 
subject: Problems running jar file