Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 30-04-2009
Member
 
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
Reply With Quote
  #2  
Old 30-04-2009
Member
 
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.
Reply With Quote
  #3  
Old 30-04-2009
Member
 
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.

Quote:
jar -cvmf user_interface_test.jar "D:\Java applications\classes"
Reply With Quote
  #4  
Old 30-04-2009
Member
 
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!
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Absolute path to run JAR file"
Thread Thread Starter Forum Replies Last Post
cannot copy file-path too long Sauvan Windows XP Support 7 13-07-2014 03:36 PM
Better amongst the absolute or relative path in HTML Galeny Software Development 3 23-12-2009 10:54 PM
How to find absolute path of a file on the server with the help of PHP function Rixwel Software Development 3 10-09-2009 09:38 AM
search for right file path if exist on Dos Clauzii Operating Systems 3 26-06-2009 11:26 AM
Cannot Specify Resource file path for c#.net 1.1 Jaheel Software Development 2 10-06-2009 08:15 PM


All times are GMT +5.5. The time now is 07:44 AM.