0

I have an Verification.jar file which is checking some conditions in excel file. I want ot create a folder called Log at the same level where that Verification.jar is present.

Thanks in Advence.........

EDIT

I am Having Folders as follows

" Verification":- Build,dist,lib,nbproject,src,Test,build.xml

"Build" Contains Classes folder

"dist" contains Verification.jar and Lib folder

"lib" Contains library files

I want to find the path of Verification.jar and create the Folder called Output .

If i change the drive it should create the folder at the same level where Verification.jar is present.

 String path= getClass().getResource("").getPath(); 

Output:--getPath:/C:/Java/jdk1.6/bin/Verification/lib/

2
  • 1
    One simple way is to pass in whatever path you'd like as a command line parameter. Commented Oct 12, 2011 at 12:55
  • Can i Find the Directory where my Verification.jar is Located Commented Oct 12, 2011 at 13:03

3 Answers 3

2

Use URL Class.getResource(String name) method.

package.ClassName.class.getClassLoader().getResource("package.ClassName"); 

EDIT:

Have a look at great SO thread - How to get the path of a running jar file? suggested by @Hovercraft Full Of Eels

Sign up to request clarification or add additional context in comments.

Comments

0

The correct form is:

String directory = System.getProperty("user.dir"); 

If You are running a .jar file it returns the present working directory, this is the directory where the .jar is located...

Note that IDEs don't run the jar file, the run the .class file where the main method is located, so when running in an IDE this method returns the projects folder

PD: Sorry if I made grammar mistakes, English is not my native language.

Comments

0

Is not the best solution, but I use this function. The jar file must be named same as the project. Works on windows and linux. If some can help me inprove it I will be honered.

public String getJarCurrentJar() { String[] userDir = System.getProperty("user.dir").split("\\"+System.getProperty("file.separator")); String appName = ""; for (String temp : userDir) { appName = temp; //Get the application name/jar } return System.getProperty("user.dir") + System.getProperty("file.separator") + "dist" + System.getProperty("file.separator") + appName+".jar"; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.