Home >
Article > Java > How does SpringBoot perform simple packaging and deployment?
How does SpringBoot perform simple packaging and deployment?
不言Original
2018-09-12 16:16:381674browse
The content of this article is about how to perform simple packaging and deployment of SpringBoot? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Preface
This article mainly introduces some packaging matters and project deployment of SpringBoot as well as solutions to some problems encountered in it.
SpringBoot packaging
In SpringBoot packaging, we use a previous web project for packaging. The first thing that needs to be clarified is whether the project is packaged in an executable jar package or a war package that runs under tomcat. Although this project is built with maven, it is more convenient to package with maven, but here is also an explanation of how to package ordinary non-maven packaged projects.
Maven packaging
First is the maven way to package: If it is jar package needs to be in pom.xml The specified package is:
jar
If it is a war package. You need to specify the package in pom.xml:
war
and use the 06db57cb000bdd2564c5b32a302b10e2 tag to exclude tomcat when packaging Dependency
After adding the corresponding tags in pom.xml, we only need to add ) Enter
mvn clean package
to complete the packaging If you want to exclude the test code, you can enter:
mvn clean package -Dmaven.test.skip=true
to package.
Generally we put the application.properties and logback.xml files in the resources folder, but after packaging, they will also be included in the jar or war package, if we want to change the configuration, it will be more troublesome. If you want to put them in the same directory as the project, application.propertiesYou can directly move them out of the directory at the same level as the project, because the Spring program will be loaded from the following paths according to priorityapplication.propertiesConfiguration file:
/config directory under the current directory
Current directory
/config directory in classpath
classpath root directory
springbootloaded by defaultlogback is in the classpath directory. At this time, we only need to specify the path of logback.xml in the application.properties configuration file. Add the following:
logging.config=logback.xml
If a third-party jar package is introduced, but it cannot be downloaded through the maven private server, you can compile it manually. For example, I wrote a tool class as Mytools, then made it into a jar package, and then placed it in my project lib directory and need to reference it, then you can compile the jar package into the local warehouse, and then pom.xmladd the corresponding name and version number. Command example:
If it is an ordinary project and is not built using maven, you can use eclipse and other tools for packaging. If it is a jar package First run the project in eclipse (run by main method), and then run it in eclipse Right-click the project export ->java -> runnable jar file-> package required libraries into generated jar Specify the main method, and then select the packaging name and packaging path. Click finish to complete packaging.
If it is a war package right-click the projectexport ->web -> war file in eclipse, and then select package The name and packaging path. Click finish to complete packaging.
Ant Packaging
After introducing the above two kinds of packaging, here is an introduction to packaging through the ant method (need to install the ant environment, installation method Basically the same as maven, specify the path and configure environment variables, I won’t go into details here). Generally after packaging, we need to put the package and configuration files in a directory. If we don’t want to copy and paste manually, we can use ant to package and integrate the packaged files. together. Here we will write a build.xml configuration file.
The above is the detailed content of How does SpringBoot perform simple packaging and deployment?. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn