I want to run Gradle application with my own parameter in NetBeans.
Example:
java - jar NameOfJarFile -MyParametere valueOfParameter
And what I must do to run my application with that parameter?
I want to run Gradle application with my own parameter in NetBeans.
Example:
java - jar NameOfJarFile -MyParametere valueOfParameter
And what I must do to run my application with that parameter?
Although this is an old thread, it might be interesting to mention that I also had this problem using Netbeans and the Gradle plugin and I found 2 solutions, one of them a 'final' one.
Solution 1: not final
I added the following line to my build.gradle file:
cmdLineArgs = '-v -test'
That seems to do the job.
When I do a normal Run Main Project or Debug Main Project in NetBeans, all goes well. I get the two parameters as arguments to my main class.
!!!However!!!: I get an error when I try to run a Clean and Build Main Project. The error is pointing to the cmdLineArgs line I added to my build.gradle file. This is the error message I get:
A problem occurred evaluating root project 'PublicApiCheckerWithGradle'.
Could not set unknown property 'cmdLineArgs' for root project 'PublicApiCheckerWithGradle' of type org.gradle.api.Project.
I still don't know why this is...
If someone has a better Gradle understanding than me and knows what causes this strange behaviour, I'm interested to know...
Solution 2: final
Right-click on the NetBeans project, select Properties and then select Custom Variables in the Categories: section of the dialogue box that opens
Add the following line in the Custom Variables: section: cmd-line-args=-v -test
Close the dialogue box
Now I can clean and rebuild, build and debug without any issues. The two arguments are always provided to my main method.
Hopefully it helps someone else too.
Best.
Ninad's answer is not valid, since the question was for a Gradle project. For Gradle projects, the project properties dialog doesn't have those options. Instead it has:
Here is what the Project Properties dialog shows:
Unfortunately, this is a question I also have. I have attempted to add a Custom Task that supplies the arguments, but when I do, I get a gradle build error which is attempting to run my first argument as a gradle task. It doesn't seem possible to supply arguments in a NetBeans gradle project.
I tried a workaround by going to the command line and running: "gradle jar" to create a jar. Then I tried the standard method of running a jar: "java -jar jarname.jar arg1 arg2" and I get an error from java that:
no main manifest attribute, in jarName.jar
Right Click your project > properties > select Run in LHS panel > in Arguments textfield - enter parameters with spaces in between.