gradle:无法执行run因为属性" mainClass"未定义或为空

时间:2016-03-09 10:49:22

标签: java netbeans gradle jar manifest

project从CLI构建并运行,然后运行:

thufir@mordor:~/NetBeansProjects/hello_client$ 
thufir@mordor:~/NetBeansProjects/hello_client$ gradle clean build;java -jar build/libs/hello_client.jar 
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 1.032 secs
hello world
thufir@mordor:~/NetBeansProjects/hello_client$ 

但Netbeans抱怨说:

Executing: gradle run
Arguments: [-c, /home/thufir/NetBeansProjects/hello_client/settings.gradle]

:run
Cannot execute run because the property "mainClass" is not defined or empty.

BUILD SUCCESSFUL

Total time: 0.17 secs

为Netbeans插件设置主类的正确方法是什么?

1 个答案:

答案 0 :(得分:7)

build.gradle文件中,您可以先应用application插件,

apply plugin: 'application'

然后指定要运行的主类:

mainClassName = 'net.bounceme.mordor.Main'

我并不真正了解Netbeans的具体内容,但application插件将为run任务提供必要的配置,以便从命令行运行,并希望从Netbeans运行。

请参阅Gralde用户指南中的此部分:https://docs.gradle.org/current/userguide/application_plugin.html