Thufir
Thufir

Reputation: 8487

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

The project builds, and runs, from the CLI fine:

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$ 

but Netbeans complains:

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

What's the correct way to set the main class for the Netbeans plugin?

Upvotes: 2

Views: 7018

Answers (1)

kdabir
kdabir

Reputation: 9868

In your build.gradle file, you can apply application plugin first,

apply plugin: 'application'

And then specify the main class to be run:

mainClassName = 'net.bounceme.mordor.Main'

I don't really know the Netbeans specific stuff here but application plugin will provide the run task with necessary configuration to run from command line and hopefully from Netbeans too.

Refer this section in Gralde user guide: https://docs.gradle.org/current/userguide/application_plugin.html

Upvotes: 8

Related Questions