springboot 发布tomcat(zip包)

本文详细介绍了如何在Spring Boot项目中配置,使得在调试时使用内置Tomcat,而在打包时过滤掉Tomcat依赖。通过Maven的assembly插件创建zip包,并提供了assembly.xml配置示例。打包完成后,将zip包改名并放置到Tomcat的appBase目录下,通过修改Tomcat的server.xml配置启动项目。最后,展示了如何通过命令行打包以及访问应用的API接口。

废话不多说

一 POM

调试时使用tomcat,打包时过滤tomcat包
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

打包插件
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/assembly.xml</descriptor>
                        <!--对应在src/main/resource包下创建assembly.xml配置文件-->
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

二 assembly.xml

具体路径根据上面plugin中来

<assembly>
	<id>test</id>
	<formats>
		<format>zip</format>
	</formats>
	<fileSets>
		<fileSet>  <!--将项目必须的文件打包到zip包根目录下-->
			<directory>${project.build.directory}/${project.build.finalName}</directory>
			<includes>
				<include>**</include>
			</includes>
			<outputDirectory>${file.separator}</outputDirectory>
		</fileSet>
	</fileSets>

</assembly>

三 启动类

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

四 打包

mvn clean package

在target目录下出现了war和zip包

打包出来的zip内容:

1 没有META-INF没有主文件

2 WEB-INF中没有web.xml

解压zip包,修改一下名字:比如我的

kintech.webCamunda-0.0.1-SNAPSHOT-test

改成

kintech.webCamunda

然后把他拷贝到一个文件夹,我拷贝到的是 D:\project  

五,设置tomcat的项目启动路径

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
<!--主要是这句Context docBase -->
	<Context docBase="D:\project\kintech.webCamunda" path="" reloadable="false" />
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

PS:windows打的是绝对路径

Lunix 打的是 /root/project     ......这样

六 启动tomcat

运行tomcat中的 startup.bat

七 访问

如下访问就可以了。

我设置了端口9022,controller也增加了test方法。

http://localhost:9022/api/test/test

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值