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

标签 java spring-boot gradle init.d

我已经使用以下 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 运行它时,出现以下错误消息:

Failed to restart project.service: Unit project.service not found.

我已经在/etc/init.d 中添加了JAR 文件的符号链接(symbolic link),但在启动时仍然显示上述错误。我在这里缺少什么?

最佳答案

尝试添加:

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 以测试您的构建是否正确

关于java - Spring Boot JAR 不作为 init.d 服务执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57322176/

相关文章:

java - 你能在 Java Bitset 中得到一组连续的位集吗?

java - Firebase 存储 Android : How can I change the the filename of a downloaded file?

java - API测试+事务回滚

maven - Gradle 中的 Maven <parent> 是什么?

spring - 错误 - 失败 : drop table if exists user - Springboot and H2

gradle - 如何在Gradle中将整数转换为int

eclipse - 如何从命令行导入Eclipse gradle项目并运行/启动配置

java - 服务器启动期间在 Tomcat、Spring、Maven 和 Eclipse 上使用 wicket 的 ClassNotFoundException

java - 使用自定义 _id 值

android - 使用 Robolectric 测试将设备上的仪器化测试添加到项目中