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

标签 java maven groovy path maven-3

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

构建时出现以下错误:

[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

我已经运行 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\

看来 maven 没有正确使用我的 JAVA_HOME 变量。

有人有办法解决这个问题吗?

这是我的主 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>

最佳答案

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

之后,我建议您重建 Maven 配置并仔细阅读 Groovy-Eclipse-Plug-in for Maven Wiki Entry并从一个像这样的更简单的配置开始,它编译 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>

重要的是 src/main/javasrc/test/java 源目录为空,如文档。 (在 Ubuntu 上使用 Maven 3.0.3、JDK 1.7.0.21 测试)

祝你好运!

关于java - 为什么系统找不到用Maven构建项目时指定的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16969225/

相关文章:

java - Tomcat - 将 war 部署到远程 tomcat 时出现 NoClassDefFoundError

unit-testing - Spock:从 CSV 文件读取测试数据

java在maven和eclipse中与clojure混合

java - InputProecssor 如何自动区分输入?

java - 在 Netty 的管道之外使用 DelimiterBasedFrameDecoder、StringEncoder 等

java - 使用图像拖放

maven - 如何让测试 jar 在 Maven 中包含依赖项?

java - 当使用运算符重载在闭包甚至方法中更新时,不会发生对列表的更新

groovy - Elasticsearch : _score always 0 in Groovy script

java - 我如何在前台获取菜单?