In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to solve the problems encountered in the operation of the springboot project into a jar package, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
The pit problem at run time after the project is packed into a jar package
A useful piece of code in my springboot project is to add the file get path code to the static directory as follows
String path=ResourceUtils.getURL ("classpath:static/task") .getPath () .replace ("% 20", ")
On the server where Ali Cloud is deployed, when running in the form of jar package, it is found that when running this part of the code, there will be a problem when you get the staic/task path and create the file through the path.
The windows system will report an exception
The linux system will create the acquired directories and folders in the same level directory as jar)
Obviously, none of this is what we want.
Solution.
Keep the original project structure, decompress the jar package and start the project by running the springboot startup class
Extract the jar command:
Jar xvf filename. Jar extracted to the current directory
Run the class command to refer to
Nohup java-cp.: / opt/homework/BOOT-INF/lib/* lemon.homework.HomeworkApplication > / opt/homework/temp.txt
Run class in the background and join the dependent jar package and output the log file to temp.txt:
The interface cannot be found after running the prompt after typing the jar package.
Using the thymeleaf template, put the html file in the templates directory of resources.
Org.springframework.boot spring-boot-starter-thymeleaf
The control layer code is:
@ RequestMapping ("login") public String login (String code, HttpServletResponse response, HashMap map) {logger.debug ("code:" + code); return "/ login";}
There is no problem with eclipse access, and the interface can be accessed normally.
However, after the jar package, the java-jar runtime prompted that the login template could not be found.
It would be nice to remove the "/" from the view name.
Thank you for reading this article carefully. I hope the article "how to solve the problems encountered when running the springboot project into a jar package" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.