Results 1 to 4 of 4
  1. #1
    robby14 is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default relative paths of ubuntu

    Hi,

    can anyone tell me how to find the relative path to the jar file when working on ubuntu. I have an application that uses some files that are in the same folder as the jar file. It works fine on windows and even on ubuntu but on ubuntu it only works when running the application from netbeans. Any help pls about what i can do... this is a bit urgent

    thanks

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default

    What technique are you using in Windows? What does that technique return when you run the program in ubuntu?


    Here are some string I got when running code:
    URL ourLoc = obj.getClass().getResource(className);

    // Output when load from a jar:
    //JAVA >Loaded from jar:file:/C:/My_Photos/SlideShowApp.jar!/ImgIdxEditor.class,
    // getFile=file:/C:/My_Photos/SlideShowApp.jar!/ImgIdxEditor.class
    //JVIEW>Loaded from systemresource:/ZIPC:\My_Photos\SlideShowApp.jar/+/ImgIdxEditor.class,
    // getFile=/ZIPC:\My_Photos\SlideShowApp.jar/+/ImgIdxEditor.class
    //JDK118>Loaded from=systemresource:/ZIP1/+/NormsTools/FindOurHome.class,
    // getFile=/ZIP1/+/NormsTools/FindOurHome.class

    // Linux: URLStr=jar:file:/home/norm/www/HTTPServer.jar!/HTTPServer/httpd.class

  3. #3
    robby14 is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default

    hi 10x 4 the reply, in windows I am just opening a file giving the path like this for example Myfolder/myfile.txt.

    in the code you have given, what is obj expected to be pls?
    thanks

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default

    obj could be the this for the calling program.

    In following test code, foh became obj in the method called:
    FindOurHome foh = new FindOurHome(); // need an object
    String theFN = FindOurHome.getHomeLoc(foh, args[0]);

    ...
    in FinfOurHome class:
    public final static String getHomeLoc(Object obj, String className) {
    ...

Similar Threads

  1. How to use relative paths when compiling?
    By chesl73 in forum New To Java
    Replies: 1
    Last Post: 10-14-2009, 02:28 PM
  2. Replies: 2
    Last Post: 10-14-2009, 05:47 AM
  3. how to set relative path in jsp?
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-02-2009, 08:20 AM
  4. Obtaining relative path outside of executable JAR
    By tjsaker in forum Advanced Java
    Replies: 1
    Last Post: 11-14-2008, 06:48 AM

Posting Permissions

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