c*****t 发帖数: 1879 | 1 How to find the jar directory my jar file is running from?
For example, my abc.jar could be run by somebody by
java -jar /some/where/abc.jar
or they could run like
java -cp /some/where/abc.jar Main
However, i needed to create/load preferences in the same directory
where abc.jar is located.
Anyone could show me howto?
Thanks a lot |
xt 发帖数: 17532 | 2 There is no good way to do it. I recommend writing a running
script along with your jar file at distribution. Then ask
the user to run your script instead of directly running
the java command. |
h*k 发帖数: 127 | 3 of course there is a good/clean way.
dont make false assumptions because you dont know.
【在 xt 的大作中提到】 : There is no good way to do it. I recommend writing a running : script along with your jar file at distribution. Then ask : the user to run your script instead of directly running : the java command.
|
d******p 发帖数: 24 | 4 If you are using jdk1.4, you can use
java.util.prefs.Preference
or you can save it to user's home dir,
which is avaliable as system property
"user.home"
【在 c*****t 的大作中提到】 : How to find the jar directory my jar file is running from? : For example, my abc.jar could be run by somebody by : java -jar /some/where/abc.jar : or they could run like : java -cp /some/where/abc.jar Main : However, i needed to create/load preferences in the same directory : where abc.jar is located. : Anyone could show me howto? : Thanks a lot
|