In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the method of java Springboot project packaging". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the method of java Springboot project packaging".
I. the way of packing
Through maven packaging, you can type it into jar, war and ear, but the common packages are jar and war.
1. Pack it into jar package:
(1) benefits
Here we execute the package command through the command window. / / notice that you go to the directory of the spring-boot-app project to execute the command:
D:\ Workspace_IDEA\ spring-boot-app > mvn-Dmaven.test.skip-U clean package
(2) execute jar package through java-jar command
Execute jar package: the packed jar package is placed in the target directory by default. At this point, we go to the target directory to execute the command:
D:\ Workspace_IDEA\ spring-boot-app\ web\ target > java-jar web-0.0.1-SNAPSHOT.jar
This startup mode is called the startup mode of jar package.
At this point, the project is started, and we can call the interface to access it through tools such as postman.
2. Pack it into a war package
Benefits: if you package it into a war package, you can also start it and access it through java-jar. Of course, another advantage is that the war package can be run in tomcat and jboss containers.
Maven is packed as jar package by default. If you want to package war package, we need to specify the packaging method as war format in pom:
War
3. Supplement:
Packaging: you need to execute the package command in the project directory, because there are pom files in the project directory, and there are maven plug-ins and other execution jar packages and war packages in this file: you need to enter the corresponding target directory, which is very simple, because the typed jar and war are placed in the target directory, and only when you enter the target directory can you see the corresponding jar and war files and execute them. II: mvn package, install commands
1 、 mvn package:
For packaging, we can find the corresponding jar package and war package in the target directory.
2. Mvn install command:
Package and put the typed jar or war package in the local warehouse
3. For example:
The spring-boot-app project is composed of three modules: web, repository and model.
Web module depends on persistence, while persistence depends on model module; the packaging mode of web module is war,model, and the packaging mode of persistence module is jar
At this point, the effect of executing the install command is:
Under the spring-boot-app project: web, persistence and model generate the corresponding war, persistence-0.0.1-SNAPSHOT.jar and model-0.0.1-SNAPSHOT.jar under their respective target directories
At the same time, the corresponding web-0.0.1-SNAPSHOT.war, persistence-0.0.1-SNAPSHOT.jar and model-0.0.1-SNAPSHOT.jar will be generated in the directories of web, persistence and model in the local repository.
Question 1. When the springboot project is packaged, if the maven reports the wrong message: missing web.xml
I >: at this point, we need the webapp directory, which corresponds to src/main and src/resource, because the default webroot for maven's web project is in src\ main\ webapp
Ii >: under the webapp directory, create a WEB-INF/web.xml
Only in this way can we package successfully, even if the web.xml is empty and there is nothing, but this can ensure that the packaging of maven is successful.
2. If mvn install does not put the packaged jar and war in the local warehouse
We need to check the configuration of Maven. It is best to write localRepository as an absolute path in settings.xml. If it is a relative path, it may cause problems:
Eg:setting.xml:
.. / apache-maven-3.3.9/.m2/repository
Location of the project:
D:\ Workspace_IDEA\ spring-boot-app
If we install under the spring-boot-app project, we may not put the packaged files in the local warehouse, but put them in the upper directory of the current location, then create the apache-maven-3.3.9/.m2/repository directory and put the packed packages in it.
This may cause us to make an error when we start the springboot project through the maven plug-in, saying that we can't find the dependency.
Thank you for your reading, the above is the content of "what is the method of java Springboot project packaging". After the study of this article, I believe you have a deeper understanding of what the method of java Springboot project packaging is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.