Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-27-2008, 07:14 PM
Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 18
jimm1 has a little shameless behaviour in the past
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?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-27-2008, 07:52 PM
Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 18
jimm1 has a little shameless behaviour in the past
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-27-2008, 08:46 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
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.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-27-2008, 08:47 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-27-2008, 09:10 PM
Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 18
jimm1 has a little shameless behaviour in the past
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-23-2008, 09:22 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 720
Nicholas Jordan is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-23-2008, 09:31 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 287
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
why don't you create shell file for launching the jar file:

Code:
#!bin/sh java -jar /path/to/the/file.jar
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 have

Last edited by serjant : 06-23-2008 at 09:34 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Resources in a JAR File JavaForums Java Blogs 0 04-15-2008 07:40 PM
Why Resources are needed in Spring FrameWork Java Tip Spring Framework 0 04-02-2008 12:40 PM
Problem locating resources on Linux. jimm1 New To Java 1 01-18-2008 08:34 PM
Why Resources are needed in Spring FrameWork JavaBean Java Tips 0 10-04-2007 11:24 PM
how to check available resources in java program lealea New To Java 3 08-13-2007 10:35 PM


All times are GMT +3. The time now is 11:43 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org