Results 1 to 7 of 7
Thread: Problem loading resources.
- 01-27-2008, 05:14 PM #1
Member
- Join Date
- Jan 2008
- Location
- South Africa
- Posts
- 18
- Rep Power
- 0
Problem loading resources.
This is a problem that has been bothering me for over a month, and I still can't find a fix, yet this problem is really simple!
I have a program (In JAR format) that loads resources from a folder (Which is in the same directory as the JAR file).
I'm using Linux. If I run the program from the shell (java -jar organiser.jar) it runs fine. But now I want to make my program more professional and user friendly, so of course I will assume normal people will double click on the JAR icon. (Normal people DO NOT USE COMMAND LINE). However unfortunately, if I try making a shortcut to the JAR, or run it from the Nautilus browser on Linux, it assumes the working directory is in my home directory, and hence looks for the resources in the wrong place! If I use getClass.getResource() that works fine, however I dont only want to read resources, I also need to write resources, and if I use relative filenames it writes/reads them from the wrong place. I do NOT want to use full pathnames, that will mean I have to have 2 versions for Linux and Windows. Is there some way of bypassing this?
- 01-27-2008, 05:52 PM #2
Member
- Join Date
- Jan 2008
- Location
- South Africa
- Posts
- 18
- Rep Power
- 0
This problem is keeping me up at night, if I don't fix this, I am going to end it all! My career as a future programmer will be ruined! And I will end up having to study something I'm not interested in.
- 01-27-2008, 06:46 PM #3
For Windows
Hello jimm1
I'm a bit new to Java, but I want to help. For Windows, I would create ".bat" files to do console related tasks that the average user does not understand. Maybe you can do the same in Lunix.
Good luck though.Eyes dwelling into the past are blind to what lies in the future. Step carefully.
- 01-27-2008, 06:47 PM #4
You can keep full paths for both linux and windows inside variables. Then in your application you can check the system (System.getProperty("os.name") and use one of the windows/linux paths only. As far as i undertand your problem, you will not need two different versions of your application in this case.
- 01-27-2008, 07:10 PM #5
Member
- Join Date
- Jan 2008
- Location
- South Africa
- Posts
- 18
- Rep Power
- 0
Ah thanks, that sounds like the simplest. I know a method for getting the location of the JAR file, but it is complex. I used a shell script (Equivalent to Window's batch file), and that also does work. But unfortunately if I make a link/shortcut to that script, it assumes the wrong working directory again.
- 06-23-2008, 07:22 PM #6
There are a lot of things in System.java that can save your carrer from ruin and your project from destruction. Be sure to read the whole thing, I will as soon as I can.
EG: Instead of using \n use System.getProperty("line.terminator"); That may be the wrong call but for example this will prevent several nasty hangs that are highly system dependent.
Additionally, I have found that proprietary win insists on occasional failure. It is definite that some things are coded such that they will eventually fail. That way the customer has to buy more software.
The new install does a .reset(); on some hidden gotchas. Be sure to have a second job as manger trainee at some fast food place down the street incase boss donut understan.
- 06-23-2008, 07:31 PM #7
why don't you create shell file for launching the jar file:
This way almost all the linux programs work,you can write or shell file either perl file for launching the application,and put it to the /usr/bin or /usr/lib according to what Linux you haveJava Code:#!bin/sh java -jar /path/to/the/file.jar
Last edited by serjant; 06-23-2008 at 07:34 PM.
Similar Threads
-
Why Resources are needed in Spring FrameWork
By Java Tip in forum Spring FrameworkReplies: 0Last Post: 04-02-2008, 10:40 AM -
Problem locating resources on Linux.
By jimm1 in forum New To JavaReplies: 1Last Post: 01-18-2008, 06:34 PM -
Why Resources are needed in Spring FrameWork
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:24 PM -
how to check available resources in java program
By lealea in forum New To JavaReplies: 3Last Post: 08-13-2007, 08:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks