无法执行目标org.apache.maven.plugins:maven-jar-plugin:2.4:jar

时间:2015-12-01 13:25:54

标签: java eclipse maven jar maven-jar-plugin

因此,我尝试继续为现有.ear项目创建maven文件,并进一步将其部署在WebLogic server上。同样,我继续创建WARJAREAR模块并按照以下步骤进行操作 -

Right click上的

parent project,选择new,选择maven module,将其命名为projectnameJARModule,然后完成wizard

创建projectnameWARModuleprojectnameEARModule模块的过程相同。制作完成后,我将WARJAR模块dependencies添加到EAR module。此外,我继续安装maven modules by { {1}}文件夹上的{1}},然后选择Right Clicking。在此之后,我在控制台中收到以下错误(下面的完整控制台日志) -

projectnameWARModule

知道如何摆脱这个?非常感谢

以下是Run As - Maven Install -

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
pom.xml

以下是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 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>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

1 个答案:

答案 0 :(得分:1)

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

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

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

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

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

  • 使用-e -X标记
  • 运行Maven构建
  • 正在运行mvn dependency:tree -Dincludes=<concerned_group_id_here>
  • 上次更改选项,将您的构建运行为mvn dependency:purge-local-repository clean install,这可以在缓存损坏的情况下工作(但错误应该不同)