简体   繁体   English

无法在 Spring 引导上构建可执行 JAR

[英]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.我目前正在阅读 Spring Boot 的教程页面( https://spring.io/guides/gs/uploading-files/#initial )以检查如何上传图像文件,但我不太明白“运行应用程序”一章的“构建可执行 JAR”部分。

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.我通过教程页面上的链接下载了项目,并复制并粘贴了所有文件,并在命令提示符下写了“./gradlew bootRun” ,就像在页面的 Build an executable JAR 部分中写的那样,但是我'我无法运行该程序。

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” .为了更具体地描述我的情况,我移动到有 gradle 文件的目录(在我的 PC 环境中,它是C:\Users\marra\Documents\workspace-spring-tool-suite-4-4.5.1.RELEASE\ImgUpload\gs-uploading-files\initial ) 通过 cd 命令,然后写入“./gradlew bootRun”并点击键盘的 Enter 按钮,但仍然只是收到错误消息“BUILD FAILED”

Here I come up with 2 questions.在这里,我提出了2个问题。

・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?换句话说,我所做的是“移动到 C:\Users\marra\Documents\workspace-spring-tool-suite-4-4.5.1.RELEASE\ImgUpload\gs-uploading-files\initial 目录并写“ ./gradlew bootRun”并按 Enter”,但这是运行教程程序的正确方法吗? 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? “您可以使用 ./gradlew bootRun 运行应用程序”是什么意思?

・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'.当我尝试运行程序但它失败时,命令提示符显示错误消息“任务':compileJava'执行失败。 > Compilation failed; > 编译失败; see the compiler error output for details.”.有关详细信息,请参阅编译器错误 output。”。 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.”.我自己做了一些研究,例如在https://github.com/realm/realm-java/issues/5910这样的页面上建议“任何编译失败都会收到此消息。”。 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.我在“./gradlew bootRun”命令中添加了“--debug”以查看我得到了什么样的错误,我得到了以下内容。

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.至少我希望我能弄清楚“从哪里看”来找到bug的原因,或者有一个适当的假设,比如“如果一切顺利,部分XXX应该显示为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.但实际上它显示为ZZZ,因此通过缩小问题的scope,可能是“AAA”部分有问题。

I've just follow up that tutorial and the.我刚刚跟进了那个教程和。 /gradlew bootRun build and run the app successfully. /gradlew bootRun构建并成功运行应用程序。 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).在这种情况下,您应该检查您的机器上安装的 java 的版本(以及 java、gradle 的版本)。 As you can see in the gradle build file there is: sourceCompatibility = '1.8' .正如您在 gradle 构建文件中看到的那样: sourceCompatibility = '1.8' If you have a java version under 1.8 your compilation will fail probably.如果你有一个低于1.8的 java 版本,你的编译可能会失败。 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 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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