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即可。

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

  • 相关阅读:
    jquery对同级的td做radio限制
    "javascript:void(0)"用法
    SQL 插入查询的最大ID 号 进行批量
    Java数字、货币值和百分数等的格式化处理
    PHP 注意问题
    Android Fragment真正意义上的onResume和onPause
    Android_CodeWiki_03
    Android_CodeWiki_02
    Android_CodeWiki_01
    Android 启动APP黑屏解决方案
  • 原文地址:https://www.cnblogs.com/lndbky/p/13650516.html
Copyright © 2011-2022 走看看