简体   繁体   English

Gradle Run引发“错误:无法找到或加载主类”

[英]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.

相关问题 Gradle:“错误:无法找到或加载主 class 主”。 通过 Gradle 构建后无法运行文件 - Gradle: "Error: Could not find or load main class Main". Can't run file after build via Gradle 摇篮,错误找不到或加载主类“ test.Main” - Gradle, error could not find or load main class 'test.Main' (Gradle)错误:无法找到或加载主 class 主 - (Gradle) Error: Could not find or load main class Main kotlin 和 gradle jar 出现“错误:无法找到或加载主 class” - kotlin with gradle jar got 'Error: Could not find or load main class ' Gradle&Groovy - 错误:无法找到或加载主类 - Gradle & Groovy - Error: Could not find or load main class Gradle、Spring 开机。 错误:无法找到或加载主 class - Gradle, Spring boot. Error: Could not find or load main class eclipse无法运行主程序“找不到或加载主类错误” - eclipse cannot run main “error could not find or load main class” Gradle - 找不到加载主类 - Gradle - Could not find load main class Gradle - 找不到或加载主类 - Gradle - Could not find or load main class JavaFX 错误:当我尝试运行我的 Z6849095FCDBF43AD7Z(IntelliJ)文件时,无法找到或加载主 class home.main - JavaFX Error : Could not find or load main class home.main with gradle (IntelliJ) when I try to run my jar file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM