I have a maven project in the latest version of Netbeans but due to an undetermined problem with my environment/maven setup I have to build the project from the command line using gmake as building with mvn clean install comes up with a lot of errors.
So, I was wondering as I'm building from the command line, when using netbeans to run the project/main class, how can I just run it without it building/compiling first - i.e. every time I right click the main class and select run file - its will say - 'Building...' - can I just run the file without building/compiling?
Thanks!
The exec-maven-plugin And we want to execute its main method from the command line via Maven. In order to do this, we can use the exec-maven-plugin. To be more specific, the exec:java goal from this plugin executes the supplied Java class with the enclosing project's dependencies as the classpath.
Running the Application Make sure to save the Java source file, right-click the project and choose Run or choose Run Project under the Run menu. Click Select Main Class.
Not found a way to run this in Netbeans, but as a workaround am running the project from the command line using:
mvn exec:java -Dexec.mainClass="com.rory.djgx.server.Main"
Just need to ensure this is executed in the root directory of the compiled classes (.class), e.g. com/rory/djgx and that the pom.xml is in this root directory.
If you want to just run the Build / Compile have an option to use all the powers of the Build Phases, as Validate, Build, Test, Package, Integration, Test, Verify, Install or Deploy. To do this you must:
-Right Click on Project -> Custom -> Goals ...
-In the Goals you can choose the more specifically option choice to build whatever you want, like Compile, Deploy, etc...
Maybe too late to answer but I had the same problem today with NetBeans 11.
You can configure this with right click on the given project and select "Properties" at the bottom of the popup menu. You need to select the "Actions" category and then select the "Run file via main()" action.
The original properties
Execute Goals:
process-classes org.codehaus.mojo:exec-maven-plugin:1.5.0:exec
Set properties:
exec.args=-classpath %classpath ${packageClassName}
exec.executable=java
exec.classpathScope=${classPathScope}
You need to change both of them
Execute Goals:
process-classes org.codehaus.mojo:exec-maven-plugin:1.6.0:java
Set properties:
exec.mainClass=${packageClassName}
exec.cleanupDaemonThreads=false
exec.classpathScope=compile
I have also changed the version (and the executed goal as well) of the maven-exec-plugin to 1.6.0
After saving the new configuration with the OK button you can right click on the edited java file and select "Run File" and the public static void main(String[] args) method will be executed.
I also attach the NetBeans screen for reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With