jar包注册为Linux服务

如果是SpringBoot项目,则需修改配置pom.xml为:

<build>

  <plugins>

    <plugin>
      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-maven-plugin</artifactId>

      <configuration>

        <executable>true</executable>

      </configuration>

    </plugin>

  </plugins>

</build>

然后使用mvn package打包即可。

CentOS6基于init.d服务:sudo ln -s /var/.../myproject.jar /etc/init.d/myjava

启动服务:service myjava start 停止服务:service myjava stop 服务状态:service myjava status 开机启动:chkconfig myjava on 日志在/var/log/myjava.log

CentOS7基于systemd部署:

在/etc/systed/system/目录下新建文件myjava.service,并写入:

[Unit]

Description=myjava

After=syslog.target

[Service]

ExecStart=/usr/bin/java -jar /var/.../myproject.jar

[Install]

WantedBy=multi-user.target

以上内容只修改Description和ExecStart后的内容。

启动服务:systemctl start myjava 停止服务:systemctl stop myjava 服务状态:systemctl status myjava 开机启动:systemctl enable myjava 日志在journalctl -u myjava

原文地址:https://www.cnblogs.com/qlong8807/p/8574147.html