无法执行目标org.apache.maven.plugins:maven-jar-plugin:2.4:jar [英] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar

查看:4924
本文介绍了无法执行目标org.apache.maven.plugins:maven-jar-plugin:2.4:jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图继续为现有的 maven 项目创建 .ear 文件并进一步部署它在 WebLogic服务器上。为此,我继续创建 WAR JAR EAR 模块并按照以下步骤操作 -

So I was trying to go ahead and create a .ear file for an existing maven project and further deploy it on WebLogic server. For the same, I went ahead to create the WAR,JAR and the EAR module and followed these steps for it -

上右键单击父项目,选择 new ,选择 maven模块,将其命名为 projectnameJARModule 然后完成向导

Right click on parent project, select new, select maven module, Named it as projectnameJARModule and then finished the wizard.

创建相同的过程一个 projectnameWARModule 和一个 projectnameEARModule 模块。制作完成后,我将 WAR JAR 模块添加为依赖项 EAR模块。此外,我继续按<$ c $安装 maven模块 c>右键单击 projectnameWARModule 文件夹中的,然后选择运行方式 - Maven安装。在此,我在控制台中收到以下错误(下面的完整控制台日志) -

Did the same process for creating a projectnameWARModule and a projectnameEARModule module. Once they were made, I added the WAR and the JAR modules as dependencies to the EAR module.Further, I went ahead to install the maven modules by Right Clicking on the projectnameWARModule folder and chose Run As - Maven Install. Upon this, I get the following error in the console (Full console log below) -

T E S T S
-------------------------------------------------------
Running org.CADJARModule.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ CADJARModule ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] projectname ............................................... SUCCESS [  0.957 s]
[INFO] projectnameJARModule ...................................... FAILURE [ 33.425 s]
[INFO] projectnameWARModule Maven Webapp ......................... SKIPPED
[INFO] projectnameEARModule ...................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.806 s
[INFO] Finished at: 2015-12-01T18:16:20+05:30
[INFO] Final Memory: 9M/126M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project projectnameJARModule: Error assembling JAR: For artifact {org.glassfish.jersey.containers:jersey-container-servlet-core:null:jar}: The version cannot be empty. -> [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/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :projectnameJARModule

任何想法我怎么摆脱这个?非常感谢

Any idea how do I get rid of this? Many Thanks

以下是父模块的 pom.xml -

Following is the pom.xml for the Parent Module -

<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>Project_name</groupId>
<artifactId>Project_name</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Project_name</name>
<build>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <configuration>
        <warSourceDirectory>WebContent</warSourceDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
    </plugin>
    </plugins>
</build>
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-json-provider</artifactId>
                <version>2.6.0</version>
        </dependency>
        <dependency>
                    <groupId>javax</groupId>
                    <artifactId>javaee-web-api</artifactId>
                    <version>7.0</version> <!-- Put here the version of your Java EE app, in my case 7.0 -->
                    <scope>provided</scope>
            </dependency>

          <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>javax.servlet-api</artifactId>
                    <version>3.1.0</version>
                    <scope>provided</scope>
            </dependency>

            <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>jstl</artifactId>
                    <version>1.2</version>
            </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
            <!-- artifactId>jersey-container-servlet</artifactId -->
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>
        </dependencies>
    </dependencyManagement>


    <properties>
        <jersey.version>2.16</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <modules>
        <module>Project_nameJARModule</module>
        <module>Project_nameWARModule</module>
        <module>Project_nameEARModule</module>
    </modules>
</project>

以下是 pom.xml WAR模块 -

    <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>Projectname</groupId>
    <artifactId>Projectname</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>ProjectnameWARModule</groupId>
<artifactId>ProjectnameWARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ProjectnameWARModule Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <finalName>ProjectnameWARModule</finalName>
</build>
</project>

以下是我的 pom.xml JAR 模块 -

Following is the pom.xml for my JAR module -

    <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>Project_Name</groupId>
    <artifactId>Project_Name</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>CADJARModule</groupId>
<artifactId>CADJARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CADJARModule</name>
<url>http://maven.apache.org</url>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
    </dependency>
</dependencies>
</project>


推荐答案

让我澄清一下: dependencyManagement 部分为定义它的同一个POM和子/模块Maven项目提供依赖关系治理。
但是,在 dependencyManagement 部分声明依赖并不意味着Maven会使用它,它只是一个提示,以防Maven将使用它以便如果某个依赖项部分中缺少版本,Maven将在 dependencyManagement 部分中查找。如果没有找到,则会产生错误(Maven无法知道要为某个依赖项解析哪个版本)。

Let me clarify: the dependencyManagement section provide dependencies governance to the same POM where it is defined and to children/modules Maven projects. However, declaring a dependency in the dependencyManagement section doesn't mean Maven will use it, it's just an hint in case Maven will use it so that if a certain version is missing in the dependencies section, Maven will look it up in the dependencyManagement section. If none is found then, an error will be generated (Maven couldn't know which version to resolve for a certain dependency).

因此,很高兴有 dependencyManagement 用于治理的部分,但它应该始终定义每个依赖项的版本,否则它将是错失的机会并使您的构建更容易出错。

Hence, good to have the dependencyManagement section for governance, but it should always define versions of each dependency, otherwise it would be a missed opportunity and make your build more error-prone.

如果您需要所有已声明的依赖项并且只在同一个声明POM的范围内,那么您实际上可以避免在 dependenciesManagement 部分所有,只需要你的依赖项部分为每个声明的依赖项提供版本。

If you need all of the declared dependencies and only in the scope of the same declaring POM, then you can actually avoid to have a dependenciesManagement section at all and just have your dependencies section providing versions for each declared dependency.

在这种情况下,你使用的是你的父POM中的 dependenciesManagement 部分(我看到它有模块),你应该检查jar模块中是否声明了相同的依赖项(如果需要),否则它不会在构建期间使用。此外,您还应检查相关模块中是否声明了另一个 dependenciesManagement 部分,并在没有版本的情况下再次声明相同的依赖关系。

In this case, you are using a dependenciesManagement section in your parent POM (I see it has modules), you should then check if in the jar module the same dependency is declared (if required), otherwise it will not be used during its build. Moreover, you should also check whether another dependenciesManagement section is declared in the concerned module and re-declaring the same dependency again without version.

可以通过以下方式提供一些额外的帮助:

Some additional helps can be provided by:


  • 使用 -e运行Maven构建 - X flags

  • 运行 mvn依赖项:tree -Dincludes =< concern_group_id_here>

  • 上次更改选项,运行构建为 mvn依赖项:purge-local-repository clean install ,这可以在缓存损坏的情况下运行(错误应该是虽然不同)

  • Running your Maven build using the -e -X flags
  • Running mvn dependency:tree -Dincludes=<concerned_group_id_here>
  • Last change option, run your build as mvn dependency:purge-local-repository clean install, which can work in case of corrupted cache (error should be different though)

这篇关于无法执行目标org.apache.maven.plugins:maven-jar-plugin:2.4:jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆