简体   繁体   中英

how to set pom.xml to run main class in maven project in netbeans

May I ask what I should do to run main class in a maven project created in Netbeans IDE? I set the pom.xml like the following, but it doesn't work.Is there any other configuration in Netbeans I should modify?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

 <groupId>com.mycompany</groupId>
 <artifactId>mavenproject2</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>jar</packaging>

 <name>mavenproject2</name>
 <url>http://maven.apache.org</url>
    <build>
        <plugins>
           <!-- <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
              </plugin> -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <mainClass>com.mycompany.mavenproject2.App</mainClass>               
            </configuration>
          </plugin>  
        </plugins>
    </build>
    <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    </dependencies>
    <properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

You can do the same in multiple ways.

  • Using command line.

mvn exec:java -Dexec.mainClass="com.example.Main" -Dexec.args="arg0 arg1"

You have not configured your pom.xml to run the main class .Also , you can configure more than one main class to execute from the main class.

The question is already been answered in stackoverflow by Mr Kai Sternad . i am sharing the link you can let me know if you are satisfied or not

How to Configure pom.xml to run 2 java mains in 1 Maven project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM