• springboot打jar包运行在linux并指定日志输出


    1.创建maven工程springboot-jar

    2.在pom.xml指定打包方式为jar

        <groupId>com.test</groupId>
        <artifactId>springboot-jar</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>

    2.在pom.xml引入springboot依赖

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <version>2.1.8.RELEASE</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
                <version>2.1.8.RELEASE</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>2.1.8.RELEASE</version>
            </dependency>
        </dependencies>

    4.指定maven打包插件

    
    
    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <encoding>UTF-8</encoding>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.1.8.RELEASE</version>
    <configuration>
    <includeSystemScope>true</includeSystemScope> //解决scope为system的jar包无法被打包进jar文件
    <mainClass>com.test.Application</mainClass>
    </configuration>
    <executions>
    <execution>
    <goals>
    <goal>repackage</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>
     

    5.controller测试类

    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * @author c
     * @date 2020/5/14 9:59
     */
    @RestController
    public class TestController {
    
        @RequestMapping("/helloworld")
        public String hello(String name) {
            return "name" + name;
        }
    
    }

    6.启动类Application

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.boot.Banner;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /**
     * @author c
     * @date 2020/5/14 10:00
     */
    @SpringBootApplication
    public class Application {
    
        private static final Logger LOG = LoggerFactory.getLogger(Application.class);
    
        public static void main(String[] args) {
            SpringApplication app = new SpringApplication(Application.class);
            app.setBannerMode(Banner.Mode.OFF);
            app.run(args);
            LOG.info("**************** Startup Success ****************");
        }
    
    }

    7.application.yml配置文件

    server:
      port: 7070
      session-timeout: 0
      context-path: /

    8.打包测试运行

    idea右上角Maven--Lifecycle--package,在项目target目录下生成两个jar文件,一个是加载maven依赖另一个没有加载,

    我们选择springboot-jar-1.0-SNAPSHOT.jar上传到linux目录下.

    启动项目:java -jar springboot-jar-1.0-SNAPSHOT.jar 但是关闭窗口项目就停止了

    后台启动项目:nohup java -jar springboot-jar-1.0-SNAPSHOT.jar &   关闭窗口不会停止项目,还会在当前目录生成nohup.out日志文件

                          nohup java -jar springboot-jar-1.0-SNAPSHOT.jar > 日志文件名.log 2>&1 &  指定生成的日志文件名

                          nohup java -jar springboot-jar-1.0-SNAPSHOT.jar >/dev/null 2>&1 &  标准输出和错误输出都丢弃

                 

  • 相关阅读:
    .NetCore 3.1和.NetCore 5.0 中WebApi的请求参数的验证方法
    php 使脚本持续的运行
    Elasticsearch es三种分页方式和对比
    es 大批量写入提高性能的策略
    php 使用多进程批量插入数据
    【转】EM算法MATLAB代码及详细注解
    【转】详解EM算法与混合高斯模型(Gaussian mixture model, GMM)
    【转】高斯混合模型
    【转】二维高斯分布(Two-dimensional Gaussian distribution)的参数分析
    word使用dot模板以spring word 模板为例
  • 原文地址:https://www.cnblogs.com/chong-zuo3322/p/12854710.html
Copyright © 2020-2023  润新知