[英]Gradle building rest spring app can't find main class
I'm trying to do a http://spring.io/guides/gs/rest-service/ tutorial, and I did everything like it is in tutorial. 我正在尝试做一个http://spring.io/guides/gs/rest-service/教程,我在教程中做了类似的事情。
When I was trying to build with gradle with the gradle.build from the tutorial gradle build failed because of missing 当我尝试使用gradle构建时,gradle.build来自教程gradle构建失败,因为缺少
springBoot {
mainClass = "main.java.hello.Application"
}
I did add it and now compilation start and finish correctly, but as soon as I'm trying to do 我确实添加了它,现在编译正确地开始和结束,但是一旦我想要做
java -jar build/libs/gs-rest-service-0.1.0.jar
java -jar build / libs / gs-rest-service-0.1.0.jar
It throws an error 它抛出一个错误
I have no idea what to do with it. 我不知道该怎么做。 Any help?
有帮助吗?
It should be hello.Application
. 它应该是
hello.Application
。 main/java
is a part of package name / project dir structure. main/java
是包名/项目目录结构的一部分。
When added the following piece of code to build.gradle : 将以下代码添加到build.gradle时 :
springBoot {
mainClass = "hello.Application"
}
both ./gradlew clean bootRun
and ./gradlew clean build
with java -jar build/libs/gs-rest-service-0.1.0.jar
work well. ./gradlew clean bootRun
和./gradlew clean build
with java -jar build/libs/gs-rest-service-0.1.0.jar
良好。
The above error is due to the build do not includes our Web RESTful Service main application class files into the gs-rest-service-0.1.0.jar
file because of the src/main/java/hello, folder is not under the gradle build scope. 上面的错误是由于构建不包括我们的Web RESTful Service主应用程序类文件到
gs-rest-service-0.1.0.jar
文件因为src / main / java / hello,文件夹不在gradle下建立范围。
In order to avoid the above error or any other errors for https://spring.io/guides/gs/rest-service/
tutorial 为了避免
https://spring.io/guides/gs/rest-service/
tutorial中的上述错误或任何其他错误
Please follow the steps below. 请按照以下步骤操作。
My Folder structure as follows. 我的文件夹结构如下。
C:\\MyWebService\\src\\main\\java\\hello
C:\\为MyWebService的\\ src \\主\\ java的\\你好
Put your build.gradle file under your main folder eg "MyWebService"
not in your hello or any other folder hence "gradle build' will be successful. 将build.gradle文件放在主文件夹下,例如
"MyWebService"
不在您的hello或任何其他文件夹中,因此“gradle build”将成功。
Using DOS cmd navigate to your main folder eg C:\\MyWebService\\
where src should be the first sub folder. 使用DOS cmd导航到您的主文件夹,
eg C:\\MyWebService\\
,其中src应该是第一个子文件夹。
Run the gradle commands. 运行gradle命令。
gradle
gradle这个
gradle tasks
gradle任务
gradle wrapper
gradle包装
gradlew clean build -- final build
gradlew clean build - 最终构建
or gradlew clean bootRun -- run before build
或gradlew clean bootRun - 在构建之前运行
You will find your gs-rest-service-0.1.0.jar
under your C:\\MyWebService\\build\\libs folder.
您将在
C:\\MyWebService\\build\\libs folder.
下找到gs-rest-service-0.1.0.jar
C:\\MyWebService\\build\\libs folder.
Finally invoke spring web service from main folder eg C:\\MyWebService\\
最后从主文件夹调用spring web服务,
eg C:\\MyWebService\\
java -jar build/libs/gs-rest-service-0.1.0.jar
java -jar build / libs / gs-rest-service-0.1.0.jar
To check Spring RESTful Web Service by hitting below url in the browser, JSON data will be returned. 要通过在浏览器中点击以下URL来检查Spring RESTful Web Service,将返回JSON数据。
{"id":1,"content":"Hello, World!"}
Now you should be successful with completing the Spring RESTful Web Service
tutorial. 现在,您应该成功完成
Spring RESTful Web Service
教程。
NB: Please do not modify your original
build.gradle
file provided on the tutorial.注意:请不要修改本教程中提供的原始
build.gradle
文件。
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'application'
Add the above highlighted line in the build.gradle 在build.gradle中添加上面突出显示的行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.