Results 1 to 2 of 2
  1. #1
    jimm1 is offline Member
    Join Date
    Jan 2008
    Location
    South Africa
    Posts
    18
    Rep Power
    0

    Default Problem locating resources on Linux.

    Hi, I'm 16, live in South Africa, and new to this forum, and have a simple problem. Let me first give you a basic overview of my program.
    It was made in NetBeans. I use Linux Ubuntu Gutsy Gibbon 7.10.
    It is called TaskOrganiser, which I want to use for managing school task's which I am assigned, and keep track of them. So I created my program, and organized it into a single JAR file, called TaskOrganiser.jar. This JAR contains a folder called META-INF, which contains the manifest file. The manifest file states the main-class, and states a class-path as "lib/AbsoluteLayout.jar". It then also contains the package "taskorganiser" and a couple of classes, such as "TaskWindow", "TaskList", "Task", "TaskGenerator", "Subject"(Enum), etc.
    The JAR was automatically created by NetBeans. This JAR is located in a folder now call TaskOrganiser, and inside this folder is also the "Lib" folder with AbsoluteLayout class, and another folder call "tasks", which is where I keep all my saved tasks (as a serialized object). Now here comes the problem.

    When I want to load my program, navigate to the directory via the shell, and type "java -jar TaskOrganiser.jar", the program executes fine and loads all the tasks. However, if I navigate to the folder using the graphical folder browser, then double click on the program, it runs, but however cannot load the tasks. When I placed the tasks folder into my home directory, it loaded them. This leads me to believe that it sets the current directory as my home directory, and searches "tasks" folder in there. This is wrong. I want to be able to load my program and its resources by clicking on it (Or even better, creating a launcher for it on my app menu), but I do not want to keep my "tasks" folder in my home directory. I want it to stay in the same folder as my JAR file. I first though of hard-coding the locations of the tasks like "/home/james/java/taskorganiser/tasks/tasklist.bin", as opposed to "tasks/tasklist.bin", but that would not be ideal. It would not work on any other computers, or on other operating systems. The only way past this problem is somehow obtaining the path of the folder which my JAR is in, then prefixing that in every file, but this is far from elegant. Any way to fix this problem? It is driving me nuts, and I'm relatively new to programming.:confused:

  2. #2
    jimm1 is offline Member
    Join Date
    Jan 2008
    Location
    South Africa
    Posts
    18
    Rep Power
    0

    Default

    OK Ive fixed the problem. I used a Shell-Script to launch the JAR, and then of course the shell-script automatically sets the working directory correctly. Is it common practice to use shell-scripts to launch Java programs in Linux, or using Batch files to launch Jar's on windows? I noticed on Linux that NetBeans uses a shell-script to launch. Any advice?

Similar Threads

  1. Replies: 6
    Last Post: 04-08-2009, 04:05 AM
  2. [SOLVED] Problem with setVisible(); on LINUX
    By lepetitprince in forum AWT / Swing
    Replies: 9
    Last Post: 11-22-2008, 04:14 PM
  3. Problem loading resources.
    By jimm1 in forum Advanced Java
    Replies: 6
    Last Post: 06-23-2008, 07:31 PM
  4. problem locating file in web application
    By Rem in forum New To Java
    Replies: 0
    Last Post: 11-09-2007, 04:00 PM
  5. problem with ServerSocket on Linux
    By gabriel in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •