标签:java maven maven-3 maven-plugin maven-assembly-plugin
我在Maven中绝对是新的,我正在研究它.
在本教程中,我有以下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.denofprogramming</groupId>
<artifactId>maventutorial1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenTutorial1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<descriptors>
<descriptor>jar-with-dependencies</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
正如您在此配置文件中看到的,它被声明为使用程序集插件,本节:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<descriptors>
<descriptor>jar-with-dependencies</descriptor>
</descriptors>
</configuration>
</plugin>
作为描述字段,它设置了值jar-with-dependencies(根据我的理解)必须创建一个新的目标jar文件,其中还包含我的项目的delcared .jar依赖项.
所以,在Eclipse中,我选择了我的项目和Run as —> Maven构建并进入目标输入部分我写下这个声明:
clean package assembly:single
必须清理我的项目的目标目录,创建包并在程序集插件上调用单个目标,将jar依赖项放入我项目的最终jar目标文件中.
问题是,这样做我在Eclipse控制台中获得以下错误消息:
.......................................................
.......................................................
.......................................................
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ maventutorial1 ---
[INFO] Building jar: /home/andrea/git/maven-java-console-application/mvntutorial1/target/maventutorial1-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-assembly-plugin:2.5.5:single (default-cli) @ maventutorial1 ---
[INFO] Reading assembly descriptor: jar-with-dependencies
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.767 s
[INFO] Finished at: 2015-07-20T15:12:19+01:00
[INFO] Final Memory: 19M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.5.5:single (default-cli) on project maventutorial1: Error reading assemblies: Error locating assembly descriptor: jar-with-dependencies
[ERROR]
[ERROR] [1] [INFO] Searching for file location: /home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies
[ERROR]
[ERROR] [2] [INFO] File: /home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies does not exist.
[ERROR]
[ERROR] [3] [INFO] File: /home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies does not exist.
[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/MojoExecutionException
它似乎找不到这个文件:/ home / andrea / git / maven-java-console-application / mvntutorial1 / jar-with-dependencies
但是根据我对本教程的理解,这不是一个配置文件,而是一个特定的Maven值,它将所有.jar依赖项放入我的最终目标jar文件中,代表我的打包项目.
为什么我会收到此错误?我错过了什么?我该如何解决?
解决方法:
看来你没有正确使用程序集插件.将插件条目更改为:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.test.MainClassName</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!-- packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
然后你只需要执行:clean install.这将在目标目录中创建具有依赖项的jar.
您可以参考以下链接给出的这些示例:https://maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html
标签:java,maven,maven-3,maven-plugin,maven-assembly-plugin 来源: https://codeday.me/bug/20190528/1169722.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。