.jar file runs fine in command line, but not from file system

Hey,

My .jar file needs and uses some files in the same directory it’s in (everything, including the jar was unzipped into said directory). It runs perfectly when I do java -jar file.jar in the command line, but there’s trouble when I double-click the file when running from the file system manager.

I’ve tried a custom command under properties ie java -jar, but the problem is that the .jar file doesn’t seem to be able to use any of the files in the same directory. When running, the jar can’t find any of the files that it needs.

Does anyone know how to solve this problem? Thanks.

Hm I’ve looked more into the problem but still haven’t got it fixed; should I be adding file names to a classpath in the custom command? So that running the jar would retrieve the necessary files.

Hello chronospher and welcome to the community!:slight_smile:

If you run it from the commandline you’re in the same folder as the jar file.
This means when you run the jar it will look in your current directory.
But when you run it from a file-manager your current directory is your home directory.
So the program will look for the files in your home directory.

You can still run it by using a command like this:

cd /<PATH>/<TO>/<JAR-file>/ && java -jar ./<JAR-file>.jar

Good luck!:wink:

Edward Iii wrote:
> This means when you run the jar it will look in your current directory.
> But when you run it from a file-manager your current directory is your
> home directory.
> So the program will look for the files in your home directory.

i think that problem is solved by setting the “java path”…a bit of
magic i don’t remember how to accomplish…but, i guess either java
docs or google knows…


DenverD (Linux Counter 282315)
CAVEAT: http://is.gd/bpoMD
posted via NNTP w/TBird 2.0.0.23 | KDE 3.5.7 | openSUSE 10.3
2.6.22.19-0.4-default SMP i686
AMD Athlon 1 GB RAM | GeForce FX 5500 | ASRock K8Upgrade-760GX |
CMedia 9761 AC’97 Audio

Hello DenverD,

This will only work if the files are classes or packages.
Because the option -classpath only tells the jvm(Java Virtual Machine) to look in that directory for classes or packages.
Here’s a bit from wikipedia:

Good luck!:wink:

It runs perfectly when I do java -jar file.jar in the command line, but there’s trouble when I double-click the file when running from the file system manager.

Is this a possible file association issue?

Which file manager are you referring to? For example, here’s how you would configure Konqeror

Chapter 8. The File Manager and Web Browser

Similar idea here

http://mandrivausers.org/index.php?/topic/9368-kde-file-associations-and-java/?