[英]Gradle Run throwing “Error: Could not find or load main class”
Project Structure is: 项目结构为:
src
---main
---test
---java
---ExecutionClass
---TestNGMain.java
build.gradle is like: build.gradle就像:
plugins {
id 'java'
}
apply plugin: 'application'
mainClassName = 'test.java.ExecutionClass.TestNGMain'
jar {
manifest {
attributes 'Main-Class': 'test.java.ExecutionClass.TestNGMain'
}
}
sourceSets {
test {
java {
srcDirs= ['src/test/java']
}
resources {
srcDirs= ['src/test/resources']
}
}
}
gradle build - works fine gradle构建-很好
gradle run - throws error "Couldn't find or Load main class" gradle run-引发错误“找不到或加载主类”
By default the application plugin only considers the main
source set as the application code for distribution. 默认情况下,应用程序插件仅将
main
源集视为分发的应用程序代码 。 If you really want to run code in a test source set, then one option is to include the test sources in the main (bad idea) 如果您真的想在测试源集中运行代码,那么一种选择是将测试源包括在主代码中(不好的主意)
sourceSets {
main{
java{
srcDir("src/test/java")
}
}
}
The mainClassName = "<package-name>.<class-name>"
in your case mainClassName = "ExecutionClass.TestNGMain"
在这种情况下,
mainClassName = "<package-name>.<class-name>"
mainClassName = "ExecutionClass.TestNGMain"
Another way is customize the main
distribution to include the test files. 另一种方法是自定义
main
发行版以包括测试文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.