seaswalker / posts

0 stars 0 forks source link

Java获取类/jar所在路径 #50

Open seaswalker opened 3 years ago

seaswalker commented 3 years ago

Spring boot:

ApplicationHome applicationHome = new ApplicationHome(App.class);
File jarDir = applicationHome.getDir();

普通的jar可以使用这个库:

<dependency>
    <groupId>org.scijava</groupId>
    <artifactId>scijava-common</artifactId>
    <version>2.85.0</version>
</dependency>

然后:

Type.load(App.class);