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.
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.
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.
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.
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?
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.
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?
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:
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
Post by:autobot
I've never won anything before. Not even a tiny ad:
a bit of art, as a gift, the permaculture playing cards