Results 1 to 4 of 4

Thread: Absolute path to run JAR file

  1. #1
    Join Date
    Apr 2009
    Posts
    67

    Absolute path to run JAR file

    Hello everyone,
    I made a research method that will allow me to retrieve the path that runs the class file. But I also want it to work for a jar.

    Please help..

    thank you

  2. #2
    Join Date
    Feb 2006
    Posts
    172

    Re: Absolute path to run JAR file

    Do you need the path to the jar, or the currently executing path? either ways method will give you the execution directory, but it won't tell you where your executing jar is actually located.

    If you are trying to load resources from your classpath and can't figure out the directory, stop where you are. Doing a new File(...) isn't going to get you what you want. Do a ClassLoader.getResourceAsStream(...), which will search your classpath for the file.

  3. #3
    Join Date
    Jan 2009
    Posts
    143

    Re: Absolute path to run JAR file

    I have followed lot of forums and blogs to find the answer for the absolute path for Jar file and I find this, the following you have to consider for your solution and for the absolute path of java jar file your location may be slight different such as instead of D drive you might be having C drive and so on.

    jar -cvmf user_interface_test.jar "D:\Java applications\classes"

  4. #4
    Join Date
    Jan 2009
    Posts
    140

    Re: Absolute path to run JAR file

    I suppose we need to hardcode the directory paths to the jar file and the images directory as a classpath option. even though it seems non-dynamic to me (meaning that the user must know where these directories are and must type/modify these paths themselves.)The method file.getAbsolutePath() returns the absolute path of the given file.

    I do not expect the user, when wanting to run the program, to type in "java -cp .;C:\path_to_jar_file;C:\path_to_jar_file\path_to_images_dir -Xmx256M -jar myprogram.jar" at the command prompt everytime. That's why I'd created a batch file to launch the program.

    Therefore, in the final analysis, Java essence can only use the absolute path to look for resources. All looking for the relative path resources are nothing more.

    Some convenient way. However, API are in the bottom to help us build the absolute path in order to find the resources!

Similar Threads

  1. cannot copy file-path too long
    By Sauvan in forum Windows XP Support
    Replies: 8
    Last Post: 31-12-2014, 03:31 PM
  2. Better amongst the absolute or relative path in HTML
    By Galeny in forum Software Development
    Replies: 3
    Last Post: 23-12-2009, 10:54 PM
  3. Replies: 3
    Last Post: 10-09-2009, 09:38 AM
  4. search for right file path if exist on Dos
    By Clauzii in forum Operating Systems
    Replies: 3
    Last Post: 26-06-2009, 11:26 AM
  5. Cannot Specify Resource file path for c#.net 1.1
    By Jaheel in forum Software Development
    Replies: 2
    Last Post: 10-06-2009, 08:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,123,335.52131 seconds with 16 queries