• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading external files from a jar

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings,

It seems that under the Linux GUI (Gnome) a Java .jar cannot read external files that are in the same directory (relative path) as the .jar. This is because when running anything in gnome, the current directory defaults to $HOME so tries to find the files there. Under Windows and Mac, this does not happen and the .jar can read external files perfectly. I can also run java -jar ProgName.jar from the linux command line and it runs perfectly. How do I get around this problem with running in the Linux GUI? Here are some of my stipulations.

1. I do not want to put my external files in a jar
2. I want to access these files with a path relative to the jar
3. I want to make it easy for the user to download and run

Should I just not worry about a jar file, and just distribute the class files instead? You may have a look at http://adornthetruth.com/nikamo to get a better idea of the program I am working on. I currently distribute it as a zip file that has to be unzipped. In the zip file is the jar plus a folder containing the external files I want the jar to read in.

-Kevin
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you could use System.getProperty() with the appropriate property to find the directory the jar file is actually in. See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties()
Maybe user.dir or java.class.path or java.library.path

Let me know how it goes..

-Aaron
http://www.weknowerrors.com
A free Wiki for error codes and computer problems.
 
Kevin Waddell
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Aaron!

The java.class.path seems to work. I had tried the user.dir before and it just gives me the same as user.home. Now my question is, currently java.class.path only has path. If at some point the class path had more than one path, would the path to my main jar always be the first one?

Thanks again, I've been pulling my hair out about this one for a while now.

-Kevin
 
reply
    Bookmark Topic Watch Topic
  • New Topic