Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jar using external file on Linux  RSS feed

 
Fabio Landoni
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I have a problem.
The situation is the following: i wrote an application which serialize on a file (dati.dat).
The application has this structur:
- pachage application
- package gui
- file dati.dat

I make the jar of my application wiht Eclipse (export->runnubla jar).

I put the jar e the dati.dat file in a folder on linux. When I opne it with double click on the jar the application doesn't find the dati.dat file.
The jar find dati.dat only when dati.dat is in the home directory.

If I ran the jar from the shell ther is no problem. the application find the dati.dat when it's in the same folder of the jar.

I've tried the following thing:

giving then

for the path's file but the problem is still here.


Printing to screen the path, I saw that the path is correct, but...


The jar must work on Linux and on windows.
In windows I have no problem. Double clic on the jar and all work properly.

Anyone can hel me?
Thanks.
 
Matt Cartwright
Ranch Hand
Posts: 152
Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the system property "user.dir" is the current working directory

when starting your jar from jexec (double-click) it is running
in your Window Manager's shell.

The Window Manager's current working directory in UNIX always
is the user's home directory.

Furthermore, you shouldn't use / (slash forward) to separate
path elements.

Either use java.io.File to build the path or java.io.File.separator
when concatinating Strings.

Hope that helps
Matt
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!