Back
Is there a Maven "phase" or "goal" to simply execute the main method of a Java class? I have a project that I'd like to test manually by simply doing something like "mvn run".
See the exec maven plugin. You can run Java classes practicing:
mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ...
mvn exec:java -
Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ...
The invocation can be as manageable as mvn exec:java if the plugin arrangement is in your pom.xml. The plugin site on Mojohaus has a more detailed example.
<project> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <configuration> <mainClass>com.example.Main</mainClass> <arguments> <argument>argument1</argument> </arguments> </configuration> </plugin> </plugins> </build></project>
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.example.Main</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
31k questions
32.8k answers
501 comments
693 users