简体   繁体   中英

Spring Boot JAR not executing as an init.d service

I have created a Spring Boot application with the following build.gradle file (Gradle version 5.4.1):

 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'
}

When I try creating a JAR using ./gradlew bootJar and running it using the following command sudo service project start , the following error message shows up:

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

I have added the symlink to the JAR file in /etc/init.d, still it displays the above error when starting. What am I missing here?

Try add :

springBoot {
    executable = true
}

I am using maven with :

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
    </configuration>
</plugin>
  1. Check if jar file permission is set executable eg (755)
  2. Try to start ./$YOURAPP.jar to test if your build was correct

first check if the project.service exists

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

if it doesnt you may need to make one. The contents of this file looks something like: https://www.baeldung.com/spring-boot-app-as-a-service

dont forget to make the script executable with chmod +x

after you make the service you need to run the folowing comantds to get it to work:

sudo systemctl restart rsyslog

sudo systemctl enable project.service

sudo service project start

sudo service project status

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM