Home > Java > javaTutorial > Can Maven Execute a Java Main Method?

Can Maven Execute a Java Main Method?

Mary-Kate Olsen
Release: 2024-11-26 05:49:10
Original
1044 people have browsed it

Can Maven Execute a Java Main Method?

Maven Run Project

Query: Can Maven execute the main method of a Java class?

Solution:

The exec Maven plugin provides the ability to execute Java classes. The syntax is:

mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ...
Copy after login

By placing the plugin configuration in your pom.xml, you can simplify the invocation to mvn exec:java.

Here's an example pom.xml configuration:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <mainClass>com.example.Main</mainClass>
                    <arguments>
                        <argument>argument1</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Copy after login

The above is the detailed content of Can Maven Execute a Java Main Method?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template