Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Problem with Jar file in Linux

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-03-2010
Member
 
Join Date: Mar 2010
Posts: 183
Problem with Jar file in Linux

Hello,
I developed an app with Eclipse / Windows and I made a JAR for easier use. When I run JAR on Windows, no problem, in any case. By cons Linux I have a little trouble: if I go through the terminal in the directory containing the JAR and I run it, it works correctly. But if I run it for example from a different directory from Gnome or by right-click + "open with" then I type "java-jar", it is not working properly. As the program loads as data from an XML file located in a subfolder, it does not find the file and the execution does not work correctly. I guess it just so the path to the "working folder" or "current directory" which works with the application once started. How do I ensure that the working folder to the execution of the application is the one containing the JAR? Any help on this is highly appreciated. Thanks in advance.
__________________
www.techarena.in
Reply With Quote
  #2  
Old 10-03-2010
Member
 
Join Date: Nov 2009
Posts: 356
Re: Problem with Jar file in Linux

Hello,
For me it is not because the concept of jar directory is a concept that is not reliable, your jar may very well be on a network, in a cache, or worse change of name, etc.

The only solutions I found to this problem
- agree in advance with the client's working directory, see Properties of a file containing this directory
- the first use, in a JDialog ask the user kindly provide a working directory and save it to a preference
- so in such style.
Reply With Quote
  #3  
Old 10-03-2010
Member
 
Join Date: Dec 2009
Posts: 202
Re: Problem with Jar file in Linux

Hello,
Even I had created a jar file on windows and now it is not working on linux operating system. So how to get the path where the JAR is placed where it is executed? It seems that all programs have a setting of environmental performance that is the way "by default" when referring to a relative path in the code. Under Windows it can be set when creating such a shortcut, and this is the field "Start in:" box properties dialog. Any help will be great. Thanks in advance.
Reply With Quote
  #4  
Old 10-03-2010
Member
 
Join Date: Nov 2009
Posts: 344
Re: Problem with Jar file in Linux

Hello,
A Java program can not be based on the position on disk jars. Or at least he can do it, but this is not a good practice. You will find many people who are brilliantly arrivals annually analyzing the classpath accessible by System.getProperty ( "java.class.path").
For your other questions:

- Yes, all programs have a default path, the problem is that this concept is not very portable, and that what one considers the implicit default is not the same as another, etc.. Under windows, sometimes it is the office; KDE, this is not the office, but HOME. Or else. Of course, it configures itself everywhere.
- How to make the log is located in the same directory as the jar? ... See above ... until your program will be launched by Java Web Start, or other.
Reply With Quote
  #5  
Old 10-03-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Problem with Jar file in Linux

Hello,
This is not the application path but the working directory. This directory is usually the directory from which you launch the program. You would have the same behavior under Windows if you throw the jar command line from another directory. But it's still possible to recover the directory eg. using the ClassLoader to retrieve the path of a class of jar, and cut the resulting URL.
Reply With Quote
  #6  
Old 10-03-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Problem with Jar file in Linux

Hello,
I think you can also use the user profile to store its data, creating a file / directory in the user.home.
Here is the code you can use
Code:
File workingdir = new File( System.getProperty("user.home"), . MyApp ");
When reading the XML, it would be best to put it in the jar and read it with a getResource (). And if ever it should be changed, you copy the directory user.home. I hope this will help you.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem with Jar file in Linux"
Thread Thread Starter Forum Replies Last Post
Go to end of file in vi editor of Linux Ooopinder Operating Systems 4 27-05-2011 11:16 AM
which one is the best file system for linux? Schulz Operating Systems 5 07-05-2011 08:46 AM
Linux File Systems MacKenze Operating Systems 4 28-01-2011 04:17 PM
what is Log File Analysis in linux Raulf Operating Systems 5 09-04-2010 11:35 AM
What is a jigdo-file in linux? Zipp Operating Systems 3 09-02-2009 08:44 PM


All times are GMT +5.5. The time now is 12:08 PM.