目录

获取各种路径

获取spring boot 可执行jar包所在路径

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);

		ApplicationHome home = new ApplicationHome(DemoApplication.class);
		home.getDir();    // returns the folder where the jar is. This is what I wanted.
		home.getSource(); // returns the jar absolute path.
//输出如下:
//C:\Users\foo\IdeaProjects\code-snippet\spring-boot\demo\target
//C:\Users\foo\IdeaProjects\code-snippet\spring-boot\demo\target\demo-0.0.1-SNAPSHOT.jar
	}
}

未完待续

References