Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm after some fairly trivial information. I've put in some good effort to Google as much as possible but I don't seem to be getting anywhere.

Essentially, I have a system which requires launching a JAR file from a different directory than the current working directory. Under Windows, from command prompt, this is the command line I'm attempting to get working:

C:\a\b\c>java -Djava.library.path=. -jar C:\x\y\z\name.jar


However this does not retain the current working directory. Instead, the working directory is changed to "C:\x\y\z". This is behaviour which I don't want to happen, I need the current working directory to remain the directory where the command was called from.

The few results I have come across have specified that this should be the case. Java should retain the working directory of the parent process (in this case, the command prompt) however I'm finding this doesn't work.

Do I need to do anything in particular to retain the current working directory?

Thanks

What I have tried:

Googled answers for retaining working directory.
Attempted many different combinations of the Java command line with different parameters.
Posted
Updated 22-Feb-16 0:42am
Comments
Richard MacCutchan 22-Feb-16 5:56am    
How do you determine that the cwd has been changed?
Mohibur Rashid 22-Feb-16 6:15am    
have try cp or classpath?
java -cp C:/x/y/z/class1.jar;c:/some_directory/

above example C:/x/y/z/class1jar. absolute path
c:/some_directory/ all class
Chris Copeland 22-Feb-16 6:44am    
Thanks for the input, I managed to resolve this using the classpath parameter and manually specifying the JAR path and lib directory.

1 solution

I managed to get this working by using the class-path command line in place of the -jar argument. In order to get this working I used:

C:\a\b\c>java -cp "C:\x\y\z.name.jar";lib\* path.to.main.Class


Thanks to Mohibur Rashid for providing the direction!
 
Share this answer
 
Comments
Richard MacCutchan 22-Feb-16 8:17am    
Which is a solution to a different question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900