2

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?

Thufir
  • 8,216
  • 28
  • 125
  • 273
  • `if (!hasProperty('mainClass')) { ext.mainClass = 'net.bounceme.mordor.Main' }` seems to fix Netbeans, but doesn't work for me from the CLI. http://stackoverflow.com/a/35061812/262852 – Thufir Mar 09 '16 at 10:57

1 Answers1

8

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

kdabir
  • 9,623
  • 3
  • 43
  • 45
  • yes, I tried that, not sure why, but that plugin caused a gradle build problem. – Thufir Mar 09 '16 at 11:29
  • I just tried that and it works on the project that you mentioned. run `gradle run` from command line – kdabir Mar 09 '16 at 11:32
  • I'll play with it. It seemed to bring up a tangential problem, so I asked http://stackoverflow.com/questions/35890436/cannot-add-gradle-application-plugin before your response. LOL. I can delete that question, maybe too much. – Thufir Mar 09 '16 at 11:35
  • heh, never did a pull request before, so just copied/pasted your solution. thanks, though :) **and Netbeans now runs the Java SE from the IDE, which is an added bonus**, however, I'm not quite sure that this the "official" and correct way to use the plugin. Works for now. – Thufir Mar 09 '16 at 11:45
  • If you want to specify custom application arguments you can add "cmd-line-args=my custom args" to Properties - Custom variables like it was dscribed here: https://github.com/kelemen/netbeans-gradle-project/wiki/Custom-variables-(properties) – Steffen Dec 05 '17 at 08:04