zoukankan      html  css  js  c++  java
  • linux 运行jar包和war包

    idea中默认打jar包

    将jar包随便放在哪个目录下,java -jar jar包名称运行

     在浏览器中运行不需要加项目名

    运行war包

    1.修改pom.xml文件

     2.SpringBoot的pom文件中将web启动器中的tomcat依赖排除,因为我们打包的war项目要放在自己的tomcat服务器中运行,需要排出SpringBoot项目内置的tomcat。然后再手动的将tomcat插件

    依赖过来,并设置其scope值为provided。

    <!--配置SpringBoot的web启动器-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <!--排除web启动中自动依赖的tomcat插件-->
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!--
        手动依赖tomcat插件,但是表明项目打包时该依赖不会被打进去,目的主要是保证开发阶段本地SpringBoot
        项目可以正常运行
    -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。
            相当于compile,但是打包阶段做了exclude操作-->
        <scope>provided</scope>
    </dependency>

     

    3.SpringBoot的启动类继承SpringBootServletInitializer,并重写configure

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {

    //重写配置方法
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
    }

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

    }

    }

    4.确认webapp及其子目录存在,且web.xml位于WEB-INF目录下,否则打包提示错误

     5.使用install命令打包项目,并将war包放到tomcat下的webapps下,启动tomcat即可。

    在浏览器中运行需要在请求前添加项目名

  • 相关阅读:
    解决ValueError: Some of types cannot be determined by the first 100 rows,
    关于number_format的一个报错
    关于IPV6审核被拒问题处理
    项目集成三方库由静态库转为动态库遇到的问题总结
    Swift判断对象属于什么类型
    运行项目报错 报scandir() has been disabled for security reasons
    CocoPods port 443
    Jetpack学习-WorkManager
    Jetpack学习-Paging
    Jetpack学习-Navigation
  • 原文地址:https://www.cnblogs.com/lndbky/p/13650516.html
Copyright © 2011-2022 走看看