【问题标题】:how to set pom.xml to run main class in maven project in netbeans如何设置 pom.xml 以在 netbeans 的 maven 项目中运行主类
【发布时间】:2016-01-27 00:47:23
【问题描述】:

请问我应该怎么做才能在 Netbeans IDE 中创建的 maven 项目中运行主类?我将 pom.xml 设置如下,但它不起作用。Netbeans 中还有其他配置需要修改吗?

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

【问题讨论】:

标签: java maven netbeans


【解决方案1】:

您可以通过多种方式做到这一点。

  • 使用命令行。

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

【讨论】:

    【解决方案2】:

    您尚未配置 pom.xml 以运行主类。此外,您可以配置多个主类以从主类执行。

    Kai Sternad 先生已经在 stackoverflow 中回答了这个问题。我正在分享链接,您可以告诉我您是否满意

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      • 2012-02-25
      • 2021-07-11
      • 2013-11-21
      • 2015-05-10
      • 2011-06-16
      相关资源
      最近更新 更多