Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get the directory path where the jar package is located after the SpringBoot project jar is released

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to get the directory path where the jar package is located after the release of the SpringBoot project jar, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article, without saying much, let's take a look at it.

SpringBoot project jar release gets the path to the directory where the jar package is located: ApplicationHome ah = new ApplicationHome (getClass ()); File file = ah.getSource (); System.out.println (file.getParentFile (). ToString ())

Description:

This method obtains the benefit of the path where the jar package is located, and will accurately obtain the path of the jar based on whether it is currently in the local test environment or published to the production environment.

SpringBoot executable jar runtime output file path problem

Under the environment of Ubuntu system, the project runs the project generation file in the form of jar package and gets the path setting of the file.

1. Use the following methods in the previous project to get the directory when typing the war package and running the project locally.

What is obtained in IDEA is: / home/xxx/xxx/ (projectName) / target/classes

If you use what you get in the jar package: / home/xxx/BOOT-INF/classes

String path = (String.valueOf (Thread.currentThread (). GetContextClassLoader (). GetResource (") .replaceAll (" file:/ ",") .replaceAll ("% 20", ") .trim ()

two。 When the project runs with java-jar xxx.jar in the jar package, jar runs as a separate file and the file is not generated in the jar package.

So use System.getProperty ("user.dir"); to get the path where the current jar is running (the same directory as the jar file), and use that path as the root directory to store the files generated in the project.

The above is how to get the directory path where the jar package is located after the release of the SpringBoot project jar. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report