简体   繁体   English

无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:compile

[英]Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile

Given the below pom.xml: 给定以下pom.xml:

<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.myApp</groupId>
    <artifactId>malloc</artifactId>
    <version>0.0.1</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <repositories>
        <repository>
            <id>project</id>
            <url>file:///${basedir}/lib</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.myApp</groupId>
            <artifactId>myApp.core</artifactId>
            <version>1.0.0</version>
        </dependency>
        ... //other dependencies
    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                        <addClasspath>true</addClasspath>
                         </manifest>
                         <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <webResources>
                         <webResource> 
                           <directory>${project.build.directory}/WebContent/WEB-INF</directory> 
                           <includes> 
                             <include>web.xml</include> 
                           </includes> 
                           <targetPath>WEB-INF</targetPath> 
                           <filtering>true</filtering> 
                         </webResource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                            <outputDirectory>${project.build.directory}/WebContent/WEB-INF/lib</outputDirectory>
                            <includeScope>runtime</includeScope>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

And the following project structure: 以及以下项目结构:

在此处输入图片说明

I expect the maven-dependency-plugin would copy all the dependencies to the WebContent/WEB-INF/lib but when I run 我希望Maven-dependency-plugin会将所有依赖项复制到WebContent / WEB-INF / lib,但是当我运行时

mvn clean install

The following error is generated: 生成以下错误:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building api-malloc 0.0.1
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.oracle:ojdbc6:jar:10.2.0.4.0 is missing, no dependency information available
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ api-malloc ---
[INFO] Deleting C:\Development\malloc\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ api-malloc ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ api-malloc ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to C:\Development\malloc\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Development/malloc/src/com/myApp/api/malloc/dto/RegionTypeDTO.java:[3,34] package com.myApp.api.core.dto does not exist
[ERROR] /C:/Development/malloc/src/com/myApp/api/malloc/dto/RegionTypeDTO.java:[5,39] cannot find symbol
  symbol: class IDTO
[INFO] 26 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.209 s
[INFO] Finished at: 2015-11-26T15:33:40-05:00
[INFO] Final Memory: 21M/227M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project malloc: Compilation failure: Compilation failure:
[ERROR] /C:/Development/malloc/src/com/myApp/api/malloc/dto/RegionTypeDTO.java:[3,34] package com.myApp.api.core.dto does not exist
[ERROR] /C:/Development/malloc/src/com/myApp/api/malloc/dto/RegionTypeDTO.java:[5,39] cannot find symbol
[ERROR] symbol: class IDTO

[ERROR] location: class com.myApp.api.malloc.controllers.TestController
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I noticed the WEB-INF/lib folder is always empty, maven dependencies are not copied over. 我注意到WEB-INF / lib文件夹始终为空,没有将Maven依赖项复制过来。

I am suspecting the copy-dependencies plugin didn't get run before the compile stage but I can't really figure out - anything that I missed? 我怀疑复制依赖插件在编译阶段之前没有运行,但是我无法弄清楚-我错过了什么吗?

The copy-dependencies goal indeed will never be executed if the compilation fails because its binding is to the package phase, which comes after the compile phase (to which by default is linked the Maven Compiler Plugin). 如果编译失败,则copy-dependencies目标的确不会执行,因为它的绑定是在compile阶段之后的package阶段(默认情况下,将Maven编译器插件链接到该阶段)。

If you want it to run before the compile phase, you need to change the phase value of the execution of the copy-dependencies goal. 如果希望它在compile阶段之前运行,则需要更改copy-dependencies目标执行的阶段值。 Changing to process-resources should be fine and should also make sense. 更改为process-resources应该很好,而且也很有意义。

<phase>package</phase>

For a full description of phases, you can check official documentation, here . 有关阶段的完整说明,您可以在此处查看官方文档。

You should also fix the compilation errors the build output is pointing at. 您还应该修复构建输出所指向的编译错误。 I see the sourceDirectory element is overriding what Maven uses by default for Java source code ( src\\main\\java ), hence I suppose your code is directly under the src folder. 我看到sourceDirectory元素覆盖了Maven默认用于Java源代码( src\\main\\java )的内容,因此我想您的代码直接位于src文件夹下。

Updated : the package X does not exist error occurs when the code is referring to a package not resolved by the Java compiler, hence it is not able to see that package in the classpath, which means in the declared dependencies: does myApp.core contain that package and class? 更新 :当代码引用Java编译器未解析的包时,发生the package X does not exist错误,因此无法在类路径中看到该包,这意味着在声明的依赖项中: myApp.core包含那包和课? If yes, then the repositories element (the lib folder) is probably not properly providing the myApp dependency. 如果是,则repositories元素(lib文件夹)可能未正确提供myApp依赖项。

You can try to install the dependency locally in your .m2 maven cache using the Maven Install Plugin as specified here . 您可以尝试使用此处指定的Maven安装插件在.m2 maven缓存中本地安装依赖项。 You could execute from the command line as following: 您可以从命令行执行,如下所示:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file  
       -Dfile=lib\myApp.core-1.0.0.jar \
       -DgroupId=com.myApp \
       -DartifactId=myApp.core \
       -Dversion=1.0.0 \
       -Dpackaging=jar \

Side note: Maven prefers lower case groupid and artifactid tokens. 旁注:Maven更喜欢小写的groupid和artifactid令牌。 Moreover, instead of using Camel Case (ie myApp ), Maven convention is also use a dash for separating tokens (ie myapp-core ). 而且,除了使用Camel Case(即myApp )之外,Maven约定还使用破折号来分隔令牌(即myapp-core )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 MAVEN 构建并出现错误 - 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile - Unable to Build using MAVEN with ERROR - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) Maven:未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.10.1compile: - Maven: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile Intelij IDEA-无法执行目标org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile - Intelij IDEA - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile 无法执行目标org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1 - org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1 Maven 构建编译错误:无法在项目 Maven 上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) - Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven org.apache.maven.lifecycle.LifecycleExecutionException:无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:编译Spring Cloud - org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile Spring Cloud Maven-无法使用Java 10执行目标org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile - Maven - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile Using java 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM