Question

Is there a way to change working dir for JVM when running Java Webstart? When i use system.setProperties("user.dir", newDir) it sets it(system.getProperties() shows it does) but ignores it.

Is this a limitation in Java Webstart to always use the working dir where i started the jnlp file? I am using all permissions in the jnlp file.

Please help!

EDIT: Whatever i do now, my webstart always uses user.dir to save files. Frustrating!

Was it helpful?

Solution

I've had this question in the past myself, but I've always found that, in the end, I didn't need it. Why do I say this?

Because your java web start app is not like an executable run from Program Files. It doesn't even exist on your computer like most programs (it is broken up into a bunch of different files and reassembled by the JVM). Therefore, you cannot say that the program has its own directory to do what it needs.

But it doesn't need to. Here's why:

  1. Java has the Preferences API to help when you need to store data. The under-workings of the Preferences API is as mysterious as JWS, thus they are really a perfect fit. Either way, if you need to write things to a file, you should check this API to see if it can meet your needs.
  2. If you need to write files for the user, then prompting them and allowing them to choose the location obviously means you won't use your current working directory to read/write files.
  3. If you need to serialize objects, you should just create a program directory using the user.home resource as @AndrewThompson suggested. This will be "your" directory and is as good (in fact, better) than a directory in Program Files (if you're running on Windows, as an example).

In conclusion, in all cases (that I've come across), there's no need to change your current working directory. If you need your own folder, create one in user.home (because you won't run into file permissions issues there).

OTHER TIPS

..all my settings file i use is created in the user.dir.

There is the mistake. Put them in a sub-directory of user.home & the problem is solved.

In the hypothesis you really really need to divert user.dir property for Java WebStart execution, here is the only option I have found: set this system environment variable (so system wide):

_JAVA_OPTIONS="-Duser.dir=C:\Temp"

But care about it, this option is read and applied to any JVM executions.

Why was it required in my context ? Because Java WebStart ClassLoader was looking for any single resource (class, properties...) in user profile before getting it from jar files in cache. As the user profile has been moved to a network storage, application start up became terribly slow. I am still investigating Java sources to understand (and avoid) this behavior. So my applications work perfectly without setting user.dir but that was the only work-around for the performance issue we got at the moment.

The recommended way to pass runtime parameters or user specific setting is through the jnlp argument

<application-desc main-class=".....">
   <argument>user.home</argument>
   ..............
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top