Spring Boot JAR不能作为init.d服务执行

3

我创建了一个使用以下build.gradle文件(Gradle版本为5.4.1)的Spring Boot应用程序:

 plugins {
    id 'org.springframework.boot' version '2.1.6.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

bootJar {
    launchScript()
}

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '2.1.6.RELEASE', ext: 'pom'
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.6.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.1.6.RELEASE'
    compile group: 'org.springframework', name: 'spring-orm', version: '5.1.7.RELEASE'
    compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
    compile group: 'org.hibernate', name: 'hibernate-hikaricp', version: '5.3.10.Final'
    compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
}

当我尝试使用./gradlew bootJar创建JAR并使用以下命令sudo service project start运行它时,会显示以下错误消息:

无法重启project.service:找不到单元project.service。

我已经将符号链接添加到/etc/init.d中的JAR文件,但在启动时仍显示以上错误。我错过了什么?
2个回答

1

Try add :

springBoot {
    executable = true
}

我正在使用Maven,带有以下内容:
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
    </configuration>
</plugin>
  1. 检查jar文件权限是否设置为可执行,例如(755)
  2. 尝试启动./$YOURAPP.jar以测试您的构建是否正确

0

首先检查项目服务是否存在

sudo vim /etc/systemd/system/project.service

如果不存在,你可能需要创建一个。这个文件的内容看起来像这样: https://www.baeldung.com/spring-boot-app-as-a-service

别忘了使用chmod +x使脚本可执行。

在创建服务后,您需要运行以下命令才能使其正常工作:

sudo systemctl restart rsyslog

sudo systemctl enable project.service

sudo service project start

sudo service project status


你也可以手动运行应用程序以查看是否正常工作:sudo java -jar /path/to/your-app.jar - Slobodan Margetić

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接