1. 程式人生 > >springboot打成war包

springboot打成war包

分散式專案:

結構:

parent:

main:

web:

service:

直接粘程式碼:

parent的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <
modelVersion>4.0.0</modelVersion> <groupId>com.wdh.springboot</groupId> <artifactId>demo-parent</artifactId> <version>1.0-SNAPSHOT</version> <modules> <module>demo-main</module> <module>demo-service</module
> <module>demo-web</module> </modules> <packaging>pom</packaging> <!-- 定義版本號 --> <properties> <spring.boot.version>1.2.2.RELEASE</spring.boot.version> <mybatis.version>3.2.7</mybatis.version> <
mybatis.page.version>3.7.5</mybatis.page.version> <mybatis-spring.version>1.2.2</mybatis-spring.version> <mybatis-generator.version>1.3.2</mybatis-generator.version> <jdbc.driver.groupId>mysql</jdbc.driver.groupId> <jdbc.driver.artifactId>mysql-connector-java</jdbc.driver.artifactId> <jdbc.driver.version>5.1.22</jdbc.driver.version> <httpclient.version>4.3.6</httpclient.version> <httpclient.httpcore.version>4.3.2</httpclient.httpcore.version> <jackson.version>2.3.3</jackson.version> <servlet.version>3.0.1</servlet.version> <jstl.version>1.2</jstl.version> <jsp.version>2.0</jsp.version> <javax.validator.version>1.1.0.Final</javax.validator.version> <javax.el.version>2.2</javax.el.version> <!-- Plugin的屬性 --> <maven-war-plugin.version>2.4</maven-war-plugin.version> <requireMaven.version>3.0.3</requireMaven.version> <java.version>1.8</java.version> <resources.encoding>UTF-8</resources.encoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties> <dependencyManagement> <dependencies> <!-- Springboot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring.boot.version}</version> <!-- 移除嵌入式tomcat外掛 --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <version>${spring.boot.version}</version> <!--<scope>provided</scope>--> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>${mybatis.page.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis-spring.version}</version> </dependency> <!-- mysql --> <dependency> <groupId>${jdbc.driver.groupId}</groupId> <artifactId>${jdbc.driver.artifactId}</artifactId> <version>${jdbc.driver.version}</version> <scope>runtime</scope> </dependency> <!-- http --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${httpclient.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>${httpclient.httpcore.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <!-- servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>${javax.validator.version}</version> </dependency> <dependency> <groupId>javax.el</groupId> <artifactId>el-api</artifactId> <version>${javax.el.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>${jsp.version}</version> <scope>provided</scope> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> </exclusions> </dependency> <!-- jackson --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> </dependencies> </dependencyManagement> <!-- 打包外掛 --> <build> <finalName>hehe</finalName> <plugins> <!-- war打包外掛, 設定war包名稱不帶版本號 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>${maven-war-plugin.version}</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*</include> </includes> <filtering>false</filtering> </resource> </resources> </build> </project>
main的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>