美文网首页
IDEA中将springboot项目打成war包

IDEA中将springboot项目打成war包

作者: 清_晨_ | 来源:发表于2018-12-07 17:39 被阅读43次

springboot打成war包和jar包有点区别,在此记录一下,方便以后使用。

1.启动类Application需要修改,具体代码如下:

springboot每个版本的配置方法可能不太一样,我本地用的是1.5.10

package com.geneator.test.demo;

import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.builder.SpringApplicationBuilder;

import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
@MapperScan(
        basePackages = {"com.geneator.test.demo"},
        annotationClass = Mapper.class)

public class DemoApplication extends SpringBootServletInitializer {
    public DemoApplication() {
    }
    public static void main(String[] args) {
        (new SpringApplicationBuilder(new Object[]{DemoApplication.class})).web(true).run(args);
    }
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        SpringApplicationBuilder rest = builder.sources(new Class[]{DemoApplication.class});
        return rest;
    }
}

2.pom.xml中的配置如下:

    <groupId>com.geneator.test</groupId>
    <!--打成包的名字-->
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
 <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.js</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>
<!--mybatis 自动生成dao,model,mapper,generaotr插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                    <webResources>
                        <resource>
                            <directory>src/main/resources</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

3.点击maven管理界面,先点击clean,而后点击package打包,最后在target目录下会生成相应的war包

maven
image.png

然后将war包拷出来放到tomcat的相应的目录下,启动tomcat就可以了。

相关文章

网友评论

      本文标题:IDEA中将springboot项目打成war包

      本文链接:https://www.haomeiwen.com/subject/pcpthqtx.html