Forums Register Login

user.dir

+Pie Number of slices to send: Send
Hi.

I wrote an executable jar that needs to, among other things get the current working directory (cwd). Whenever I get this property the cwd always seems to default to the C:\Windows\System32 directory.

OS: Windows 7 - 64 bit
Java version: 1.6.0_21

The strange thing is, it worked before, meaning the correct cwd was retrieved. I haven't executed this jar file for a weeks now, so something must've changed OS-wise. I'm assuming some windows update? I really dont know. Please help

I dont have this issue on Windows XP at all by the way.
+Pie Number of slices to send: Send
Welcome to the Ranch.
Where is your jar located?
+Pie Number of slices to send: Send
. . . and how are you invoking it?

This sounds too complicated for "beginning", so I shall move the discussion.
+Pie Number of slices to send: Send
Hi.

My jar file is in my lib directory (\AppFolder\lib). The correct cwd is found when I run my application in Netbeans, but as soon as I run it outside of the IDE the cwd defaults to C:\Windows\System32. Its almost as if the JVM cannot find the cwd in Windows 7 and just starts in C:\Windows\System32.

I'm invoking it using
+Pie Number of slices to send: Send
Hi.

My jar file is in my lib directory (\AppFolder\lib). The correct cwd is found when I run my application in Netbeans, but as soon as I run it outside of the IDE the cwd defaults to C:\Windows\System32. Its almost as if the JVM cannot find the cwd in Windows 7 and just starts in C:\Windows\System32.

I'm invoking it using:
+Pie Number of slices to send: Send
I meant, how are you invoking the .jar?
+Pie Number of slices to send: Send
This is very strange. Have you set the classpath? Maybe you can write a small class which just prints out System.getProperty("user.dir"), save it on say your Desktop and run it from the command line to check what it gives?
+Pie Number of slices to send: Send
You can set the classpath for the .jar in its manifest file.
+Pie Number of slices to send: Send
I use a manifest file for all of my jars. Upon execution of my application I print the cwd using a message box. I've executed my app within netbeans, from the command line and by directly executing the jar.

netbeans and command line --> correct cwd

direct jar execution --> Mr System32

EDIT:
This really sounds like some OS issue to me, mainly because of the fact that my application worked correctly a few weeks ago without any code changes.
+Pie Number of slices to send: Send
I presume you are executing the .jar by clicking it (or its icon) and you have an association of .jar → "javaw"? As Maneesh asked, what is the classpath and what does it say in the manifest file about classpath?

You may be right about an OS problem. What did you get as user.dir previously?
+Pie Number of slices to send: Send
Yes, by clicking on it, and the file association for it is javaw.

My Manifest File


Previous user.dir:
- Previously, I was able to execute my application from any directory so the user.dir would change accordingly.
1
+Pie Number of slices to send: Send
Don't know any more. Sorry. Anybody else?
+Pie Number of slices to send: Send
Thanks Sheriff Campbell.

Appreciate the effort
+Pie Number of slices to send: Send
You're welcome, and sorry I couldn't help more.

The only thing is, if you double-click a desktop icon or similar and start javaw, is there a "current" directory at all?
+Pie Number of slices to send: Send
If it's working in NetBeans, you've probably got the "Working Directory" property set. To check, right click the project in NB, choose Properties, click the "Run" category. I'm betting that the Working Directory property is set to a specific directory. If not, NB would automatically set it to the project directory.

So, either way, when NB runs your JAR file for you, it passes the option "-Duser.dir=PathToWorkingDirectory".

So if you want to produce that same behavior from the command line, just use that option. For example:

java -Duser.dir=PathToWorkingDirectory -jar YourJarFileName.jar

Hope that helps!
+Pie Number of slices to send: Send
Hi all,
I'm new to forum but I find a similar issue and perhaps I can give more information, although not solving the problem.

I encountered a different behaviour if the java.exe executed is the one in System32 or the one in %JAVA_HOME%\bin.

If I execute "java -jar MyJar.jar" with default settings, working directory is always System32.

If I change the path var or I remove java.exe from System32 "java -jar MyJar.jar" (executing %JAVA_HOME%\bin\java.exe instead of C:\Windows\System32\java.exe), working directory is the directory from which I execute the command.

Hope this help

Bye

Armando
I've never won anything before. Not even a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 5126 times.
Similar Threads
File Not Found Exception
Problems with non-english characters
java read file problem
Windows cmd line args with wildcards
how to delete an object from heap ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:27:44.