Add Other Java File To Maven Project Create AppUtil.java file as below. Here the main class being com.mycompany.App If you would like to pass parameters, you can use exec.args option as follows. Maven exec plugin lets you run the main method of a Java class in your project, with the project dependencies automatically included in the classpath. Press Ctrl+S and close the file. I am trying to run a simple Java project. Maven Run Command Maven's exec plugin can be used to run any of the main class generated in the target folder. The “Hello World” is just printed in the main method of App class. -cp is the abbreviation of “class path” which means find the java class in the after jar file.
To run the Java main method from Maven… In the Maven project, you specify the main class details by updating the pom.xml file. The com.example.bank.App class in the project is the main class that will be executed when you execute the JAR file. I have one main class called 'TestMain'.
SpringApplication.run(Classname.class, args) bootstraps a spring application as a stand-alone application from the main method. Recently I was working on a project using Maven, and I really wanted to be able to run the project easily without needing to worry about all the classpath entries. Running from Command line Suppose we have the project created in the previous chapters. When I tried to run the project using right click -> run, there was no menu to run the application as 'Run As Java Application'.
1) Running from Command line I had created a project using the 'Maven Project' type. You successfully updated your pom.xml file. Posted on December 22, 2010 by Mark Nelson. We can use Maven exec plugin to run the main method of a Java class, with the project dependencies automatically included in the classpath. I am wondering where that option has gone.
This article show you 3 ways of using the maven exec plugin to run java, with code examples.