Can't produce an executable jar from Spring Bo

2019-09-05 07:56发布

问题:

I have created a Spring Boot Microservice using IntelliJ-Idea and Gradle as the build engine. I have made no changes to the initial Spring Boot configuration. I also have made no modifications to the build.gradle file provided. I built the application using starter.spring.io through IntelliJ-Idea and have the following dependencies:

compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')

The application currently contains 12 classes and 2 interfaces and is a Web Service provider. It runs fine on my system but when I build with Gradle, the Manifest.MF contains no Main-Class entry.

I created a very simple Hello World app and tried several combinations of IDE’s and build tools(Gradle and Maven) and got the following results:  

 

Interestingly, I was able to produce executable jars in Eclipse which has a separate Runnable JAR Export process.

I'm fairly new to IntelliJ and Gradle. Has anyone see this behavior before? Any ideas what I might be doing wrong in IntelliJ? I have my Hello World project zipped up if anyone needs it.

回答1:

I took the advise of M. Denium and I did the Gradle build from the Command Line. The jars created were formatted correctly to be executable. Everything worked like a charm. In fact the Main-Class is a Spring Boot class called org.springframework.boot.loader.JarLauncher and the main class for my app was in a property called Start-Class. The IDE totally misses this.



回答2:

Looks like you will need to include spring boot plugin for gradle - org.springframework.boot:spring-boot-gradle-plugin

More details in the gradle section of the getting started guide