Gradle - 无法找到或加载主类 [英] Gradle - Could not find or load main class

查看:692
本文介绍了Gradle - 无法找到或加载主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Gradle运行一个非常简单的项目,并在使用 gradlew run命令时遇到以下错误:

I'm trying to run a very simple project using Gradle and running into the following error when using the gradlew run command:

无法找到或加载主类'hello.HelloWorld'

这是我的文件结构:

Here is my file structure:

SpringTest
    -src
        -hello
            -HelloWorld.java
            -Greeter.java
    -build
         -libs
         -tmp
    -gradle
         -wrapper
    -build.gradle
    -gradlew
    -gradlew.bat

我排除了libs和tmp文件夹的内容, t认为这将是这个问题的相关信息,但我可以添加它,如果需要的话。

I excluded the contents of the libs and tmp folders because I didn't think that would be relevant information for this issue, but I can add it in if need be.

这是我的build.gradle文件:

Here is my build.gradle file:

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'

mainClassName = 'hello/HelloWorld'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile "joda-time:joda-time:2.2"
}

jar {
    baseName = "gs-gradle"
    version = "0.1.0"
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

关于如何解决这个问题?我已经为mainClassName属性尝试了各种各样的东西,但似乎没有任何工作。

Any idea on how to fix this issue? I've tried all sorts of things for the mainClassName attribute but nothing seems to work.

推荐答案

我在这里看到两个问题,一个与 sourceSet 另一个与 mainClassName

I see two problems here, one with sourceSet another with mainClassName.


  1. 将java源文件移动到 src / main / java 而不是 src 。或正确设置 sourceSet $ b

  1. Either move java source files to src/main/java instead of just src. Or set sourceSet properly

sourceSets.main.java.srcDirs = ['src']


  • mainClassName 应该是完全合格的类名称,而不是路径。

  • mainClassName should be fully qualified class name, not path.

    mainClassName = "hello.HelloWorld"
    


  • 这篇关于Gradle - 无法找到或加载主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆