java 为什么用Maven构建项目时系统找不到指定的路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16969225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 00:34:08  来源:igfitidea点击:

Why can't the system find the path specified when building project with Maven?

javamavengroovypathmaven-3

提问by glennvdv

I am trying to start a Groovy/Java project from scratch. I have created a Groovy class with a test.

我正在尝试从头开始一个 Groovy/Java 项目。我创建了一个带有测试的 Groovy 类。

When building, I am getting the following error:

构建时,我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project repository: Compilation failure
[ERROR] Failure executing groovy-eclipse compiler:
[ERROR] The system cannot find the path specified.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on projec
t repository: Compilation failure
Failure executing groovy-eclipse compiler:
The system cannot find the path specified.

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
Failure executing groovy-eclipse compiler:
The system cannot find the path specified.

        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:858)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more

I have run Process monitor to see what path's it could not find and is says the following:

我已经运行 Process monitor 以查看它找不到什么路径,并显示以下内容:

D:\Programmeren\Workspace\BirthdayAppV2\JAVA_HOME\bin\
D:\Programmeren\Workspace\BirthdayAppV2\ GROOVY_HOME\bin\
D:\Programmeren\Workspace\BirthdayAppV2\domain${env.JAVA_HOME_7}\bin\javac
D:\Programmeren\Workspace\BirthdayAppV2\domain${env.JAVA_HOME_7}\bin\

It seems maven isn't using my JAVA_HOME variables correctly.

似乎 maven 没有正确使用我的 JAVA_HOME 变量。

Does someone have a solution to this problem?

有人有解决这个问题的方法吗?

This is my main pom:

这是我的主要pom:

<?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>be.vandevelde.glenn</groupId>
<artifactId>BirthdayAppV2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>BirthdayManagerV2</name>

<properties>
    <java.version>1.7</java.version>
    <spring.version>3.2.2</spring.version>
    <groovyVersion>2.1.3</groovyVersion>
</properties>

<modules>
    <module>repository</module>
    <module>domain</module>
</modules>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>0.7-groovy-2.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>${groovyVersion}</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <!-- set verbose to be true if you want lots of uninteresting messages -->
                <!-- <verbose>true</verbose> -->
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.7.0-01</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-batch</artifactId>
                    <version>2.1.3-01</version>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.7.0-01</version>
            <extensions>true</extensions>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/main/groovy</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/test/groovy</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
                <executable>${env.JAVA_HOME_7}/bin/javac</executable>
                <fork>true</fork>
            </configuration>
        </plugin>
    </plugins>
</build>

采纳答案by Jens Birger Hahn

There is probably more than one problem with your setup. First, the output of your environment indicates that evironment variables are not properly resolved (D:\Programmeren\Workspace\BirthdayAppV2\JAVA_HOME\bin\- is this the path to your JDK?). Setting JAVA_HOME and the Maven environment variables is documented on the respective project pages. You should start with that.

您的设置可能存在多个问题。首先,您的环境的输出表明环境变量没有正确解析(D:\Programmeren\Workspace\BirthdayAppV2\JAVA_HOME\bin\- 这是您的 JDK 的路径吗?)。设置 JAVA_HOME 和 Maven 环境变量记录在各自的项目页面上。你应该从那个开始。

Afterwards, I suggest you rebuild your Maven configuration and carefully readthe Groovy-Eclipse-Plug-in for Maven Wiki Entryand start with a simpler configuration like this one, which compiles both Java 7 and Groovy files:

后来,我建议你重建Maven配置,并仔细阅读Groovy的Eclipse的插件为Maven的维基条目,并与像这样的,这条命令编译的Java 7和Groovy文件简单的配置开始:

    <?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>your.group</groupId>
        <artifactId>groovy-eclipse-compiler-maven-example</artifactId>
        <version>1-SNAPSHOT</version>
        <name>groovy-eclipse-compiler-maven-example</name>

        <packaging>jar</packaging>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.source.encoding>UTF-8</project.source.encoding>

            <java.source.version>1.7</java.source.version>
            <java.target.version>1.7</java.target.version>

            <junit.version>4.10</junit.version>
        </properties>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <includeEmptyDirs>true</includeEmptyDirs>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <compilerId>groovy-eclipse-compiler</compilerId>
                        <source>${java.source.version}</source>
                        <target>${java.target.version}</target>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.codehaus.groovy</groupId>
                            <artifactId>groovy-eclipse-compiler</artifactId>
                            <version>2.7.0-01</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>

        <dependencies>
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>2.0.4</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>

It is important that the src/main/javaand src/test/javasource directories are notempty, as mentioned in the documentation. (Tested with Maven 3.0.3, JDK 1.7.0.21 on Ubuntu)

如文档中所述src/main/javasrc/test/java源目录和源目录不为空很重要。(在 Ubuntu 上使用 Maven 3.0.3、JDK 1.7.0.21 测试)

Good luck!

祝你好运!