avatar
java directory?# Java - 爪哇娇娃
c*t
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
avatar
xt
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.
avatar
h*k
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.

avatar
d*p
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。