0 votes
1 view
ago in Java by (2.6k points)

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".

1 Answer

0 votes
ago by (26.5k points)

See the exec maven plugin. You can run Java classes practicing:

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>

...