• springboot 发布tomcat(zip包)


    废话不多说

    一 POM

    1. 调试时使用tomcat,打包时过滤tomcat包
    2. <dependencies>
    3. <dependency>
    4. <groupId>org.springframework.boot</groupId>
    5. <artifactId>spring-boot-starter-tomcat</artifactId>
    6. <scope>provided</scope>
    7. </dependency>
    8. <dependency>
    9. <groupId>org.springframework.boot</groupId>
    10. <artifactId>spring-boot-starter-web</artifactId>
    11. <exclusions>
    12. <exclusion>
    13. <groupId>org.springframework.boot</groupId>
    14. <artifactId>spring-boot-starter-tomcat</artifactId>
    15. </exclusion>
    16. </exclusions>
    17. </dependency>
    18. </dependencies>
    19. 打包插件
    20. <build>
    21. <plugins>
    22. <plugin>
    23. <groupId>org.apache.maven.plugins</groupId>
    24. <artifactId>maven-assembly-plugin</artifactId>
    25. <version>3.0.0</version>
    26. <configuration>
    27. <descriptors>
    28. <descriptor>src/main/assembly/assembly.xml</descriptor>
    29. <!--对应在src/main/resource包下创建assembly.xml配置文件-->
    30. </descriptors>
    31. </configuration>
    32. <executions>
    33. <execution>
    34. <id>make-assembly</id>
    35. <phase>package</phase>
    36. <goals>
    37. <goal>single</goal>
    38. </goals>
    39. </execution>
    40. </executions>
    41. </plugin>
    42. </plugins>
    43. </build>

    二 assembly.xml

    具体路径根据上面plugin中来

    1. <assembly>
    2. <id>test</id>
    3. <formats>
    4. <format>zip</format>
    5. </formats>
    6. <fileSets>
    7. <fileSet> <!--将项目必须的文件打包到zip包根目录下-->
    8. <directory>${project.build.directory}/${project.build.finalName}</directory>
    9. <includes>
    10. <include>**</include>
    11. </includes>
    12. <outputDirectory>${file.separator}</outputDirectory>
    13. </fileSet>
    14. </fileSets>
    15. </assembly>

    三 启动类

    1. @SpringBootApplication
    2. public class Application {
    3. public static void main(String[] args) {
    4. SpringApplication.run(Application.class, args);
    5. }
    6. }

    四 打包

    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的项目启动路径

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

    PS:windows打的是绝对路径

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

    六 启动tomcat

    运行tomcat中的 startup.bat

    七 访问

    如下访问就可以了。

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

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

  • 相关阅读:
    微服务篇之限流
    【数据库】MySQL分页查询
    CCAA 认证通用基础卷之(一)合格评定基础 第二章合格评定与国家质量基础设施 NQI (National Quality Infrastructure)
    Flutter Cocoon 已达到 SLSA 2 级标准的要求
    基于Java+Springboot+Vue+elememt宠物用品商城系统设计实现
    vue3中使用better-scroll
    csdn中书写数学公式简单介绍
    C++遴选出特定类型的文件或文件名符合要求的文件
    java线程生命周期
    03-背景属性
  • 原文地址:https://blog.csdn.net/hanjun0612/article/details/127806040