netbeans 8.1 maven无法构建项目

时间:2017-04-08 21:04:03

标签: java maven netbeans

我使用NetBeans直接创建了一个新的Maven项目(Windows 10)。出于测试目的,我的项目只有一个主要类。

public class NewClass {
    public static void main(String[] args) {
        System.out.println(1);
    }
}

这是自动生成的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
    <artifactId>mavenproject1</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

nbactions.xml

<?xml version="1.0" encoding="UTF-8"?>
<actions>
        <action>
            <actionName>run</actionName>
            <packagings>
                <packaging>jar</packaging>
            </packagings>
            <goals>
                <goal>process-classes</goal>
                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
            </goals>
            <properties>
                <exec.args>-classpath %classpath com.example.mavenproject1.NewClass</exec.args>
                <exec.executable>java</exec.executable>
            </properties>
        </action>
    </actions>

当我尝试构建项目时,我收到此错误:

cd C:\Users\myusername\abc\NetBeansProjects\mavenproject1; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_91" cmd /c "\"\"C:\\Program Files\\NetBeans 8.1\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-classpath %classpath com.example.mavenproject1.NewClass\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_91\\bin\\java.exe\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.1\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""


The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\myusername). Please verify you invoked Maven from the correct directory.
http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException

出于某种原因,它正在调查C:\Users\myusername而不是正确的项目文件夹..

有什么想法吗? (如果我使用cmd导航到项目文件夹并运行mvn package命令,一切正常)

0 个答案:

没有答案