简体   繁体   中英

Unable to Build an executable JAR on Spring Boot

I'm currently reading a tutorial page of Spring Boot ( https://spring.io/guides/gs/uploading-files/#initial ) in order to check how to upload an image file, but I don't quite understand the “Build an executable JAR” part of “Run the Application” Chapter.

I downloaded the project via the link on the tutorial's page, and copied and pasted all the files, and I wrote “./gradlew bootRun” on the command prompt, just as written in the Build an executable JAR part of the page, but I'm unable to run the program.

To describe my situation in a more concrete way, I moved to the directory where there is a gradle file (in my PC environment, it's C:\Users\marra\Documents\workspace-spring-tool-suite-4-4.5.1.RELEASE\ImgUpload\gs-uploading-files\initial ) by cd command, and then wrote “./gradlew bootRun” and hit the Enter button of the keyboard, but still just get an error message “BUILD FAILED” .

Here I come up with 2 questions.

・First of all, am I properly following the tutorial's instructions in the first place? In other words, what I did is “move to the C:\Users\marra\Documents\workspace-spring-tool-suite-4-4.5.1.RELEASE\ImgUpload\gs-uploading-files\initial directory and wrote “./gradlew bootRun” and hit the Enter”, but was this the right way of running the tutorial's program? If my way of doing it is wrong, how should I have run the program? What does “you can run the application by using./gradlew bootRun” mean?

・Another possibility of this failure is that I get an error message even though I do follow the tutorial's instructions properly. But in that case, which part did I do wrong? When I try to run the program and it fails, the command prompt shows an error message “Execution failed for task ':compileJava'. > Compilation failed; see the compiler error output for details.”. I did some research by myself, and for example on a page like https://github.com/realm/realm-java/issues/5910 suggests that “Any compilation failure gets this message.”. Perhaps I might not have copied and pasted all the sample code of the files properly, but the problem is that I don't know which folder's which file's which line to check. I added “--debug” to the “./gradlew bootRun” command to see what kind of errors I get, and I got the following.

13:28:20.806 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :compileJava FAILED        

13:28:21.249 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.

13:28:21.250 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 6s   

At least I hope that I can figure out “where to look at” to find the cause of the bug, or have a proper assumption like “If everything goes smoothly, the part XXX should be displayed as YYY. But in reality it's displayed as ZZZ, so it's possible that there is something wrong with the part AAA”, by narrowing down the scope of the problem.

I've just follow up that tutorial and the. /gradlew bootRun build and run the app successfully. In situation like this you should check what version of java you've installed on your machine(and also which version of java, gradle is using it). As you can see in the gradle build file there is: sourceCompatibility = '1.8' . If you have a java version under 1.8 your compilation will fail probably. I had also some issues in the past with Gradle building the fat boot jar, maybe that will help also: Spring boot and Gradle multi-modules project, failed to load dependencies correctly

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