Results 1 to 6 of 6

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

  1. #1

    Default .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.

  2. #2

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

    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.

  3. #3

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

    Hello chronospher and welcome to the community!

    Quote Originally Posted by chronospher
    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.
    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.

    Quote Originally Posted by chronospher
    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.
    You can still run it by using a command like this:
    Code:
    cd /<PATH>/<TO>/<JAR-file>/ && java -jar ./<JAR-file>.jar
    Good luck!
    Where did I put my coffee cup?
    dir -R /home/* | grep "coffee cup"

  4. #4
    Join Date
    Jun 2008
    Location
    Earth - Denmark
    Posts
    10,730

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

    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

  5. #5

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

    Hello DenverD,

    Quote Originally Posted by DenverD
    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..
    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:
    Quote Originally Posted by http://en.wikipedia.org/wiki/Classpath_(Java)
    ...The Classpath is an argument - set either on the command-line, or through an environment variable - that tells the Java Virtual Machine where to look for user-defined classes and packages when running Java programs....
    Good luck!
    Where did I put my coffee cup?
    dir -R /home/* | grep "coffee cup"

  6. #6
    Join Date
    Jun 2008
    Location
    Auckland, NZ
    Posts
    20,382
    Blog Entries
    1

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

    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

    Chapter8.The File Manager and Web Browser

    Similar idea here

    http://mandrivausers.org/index.php?/...ons-and-java/?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •