当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Reference directories correctly when launching a .jar from a batch file

问题描述:

This question already has an answer here:

  • How to get the path of a running JAR file?

    28 answers

网友答案:

You can ask the JVM about the location of a given class. If you know it is inside the jar you refer to, then you can then extract the location of the jar file, and then construct your file objects relative to that.

See http://stackoverflow.com/a/320595/53897 for details about

return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath());
分享给朋友:
您可能感兴趣的文章:
随机阅读: