gpt4 book ai didi

java - 如何设置pom.xml以在netbeans中的maven项目中运行主类

转载 作者:行者123 更新时间:2023-11-30 07:38:32 24 4
gpt4 key购买 nike

请问我应该怎么做才能在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>

最佳答案

您可以通过多种方式执行相同的操作。

  • 使用命令行。

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

关于java - 如何设置pom.xml以在netbeans中的maven项目中运行主类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35026857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com