java 当我尝试使用 Maven 程序集插件时,为什么会收到此错误消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31517727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why I obtain this error message when I try to use the Maven assembly plugin?
提问by AndreaNobili
I am absolutly new in Mavenand I am studying it on a tutorial.
我绝对是Maven新手,我正在教程中学习它。
In this tutorial I have the following pom.xmlconfiguration file:
在本教程中,我有以下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>
As you can see in this configuration file it is declared the use of the assemblyplugin, this section:
正如您在此配置文件中所看到的,它声明了使用程序集插件,此部分:
<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>
As descriporfield it is setted the value jar-with-dependenciesthat (from what I have understand) have to create a new target jar file that contains also the delcared .jar dependencies of my project.
作为描述字段,它设置了jar-with-dependencies值(据我所知)必须创建一个新的目标 jar 文件,其中还包含我的项目的已声明的 .jar 依赖项。
So, into Eclipse, I select my prject and the Run as---> Maven Buildand into the Goalinput section I write this statment:
因此,在 Eclipse 中,我选择我的项目和Run as---> Maven Build并进入Goal输入部分,我写了以下语句:
clean package assembly:single
that have to clean the target directory of my project, create the package and call the singlegoal on the assemblyplugin that put the jar dependecies into my final jar target file of my project.
必须清理我的项目的目标目录,创建包并调用程序集插件上的单个目标,该插件将 jar 依赖项放入我项目的最终 jar 目标文件中。
The problem is that doing in this way I obtain the following error message into the Eclipse console:
问题是,通过这种方式,我在 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
It seems that it can't find this file: /home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies
好像找不到这个文件:/home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies
But from what I have understand on the tutorial this is not a configuration file but a specific Maven value that say to put all the .jar dependencies into my final target jar file that represent my packaged project.
但是根据我在教程中的理解,这不是一个配置文件,而是一个特定的 Maven 值,它表示将所有 .jar 依赖项放入代表我打包项目的最终目标 jar 文件中。
Why I obtain this error? What am I missing? How can I fix it?
为什么我得到这个错误?我错过了什么?我该如何解决?
回答by Debojit Saikia
It seems you are not using the assembly
plugin properly. Change the plugin entry to this :
看来您没有assembly
正确使用该插件。将插件条目更改为:
<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>
Then you just need to execute : clean install
. This will create the jar with dependencies in the target
directory.
You can refer to these examples given at this link : https://maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html
然后你只需要执行 : clean install
。这将在target
目录中创建具有依赖项的 jar 。您可以参考此链接中给出的这些示例:https: //maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html
回答by SomeStudent
So this here is how my maven POM looks like in regards to the plug in.
所以这就是我的 maven POM 在插件方面的样子。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
I can only assume two things:
我只能假设两件事:
- You either did not format it properly, or the version of maven you are using doesn't support what you wish to do.
- You may have not properly set up your bash profile and stipulate where the maven directory is located. Also, if possible try setting up your maven projects via the terminal/command prompt as is displayed on the apache website and see if it works. Link is : http://maven.apache.org/archetype/maven-archetype-plugin/examples/generate-batch.html
- 你要么没有正确格式化它,要么你使用的 maven 版本不支持你想要做的。
- 您可能没有正确设置 bash 配置文件并规定了 maven 目录所在的位置。此外,如果可能,请尝试通过 apache 网站上显示的终端/命令提示符设置您的 maven 项目,看看它是否有效。链接是:http: //maven.apache.org/archetype/maven-archetype-plugin/examples/generate-batch.html
Ex: This is a command I use to create a maven archetype for one of my projects:
例如:这是我用来为我的一个项目创建 maven 原型的命令:
mvn -B archetype:generate \-DarchetypeGroupId=org.apache.maven.archetypes \-DgroupId=com.weather.mobile.ios.automation.tenday \-DartifactId=IphoneTenDayAutomation
The groupID creates the pathway (think of it like the package), while as the artificatID is the name of the class.
groupID 创建路径(将其视为包),而 artificatID 是类的名称。
回答by Balaji Sijapati
i had similar issues with maven build error. I tried checkbox on update snapshot option and fixed. It may help for those if there are old build stuff in background or something like cache.
我在 maven 构建错误方面遇到了类似的问题。我尝试了更新快照选项上的复选框并修复了。如果后台有旧的构建内容或缓存之类的东西,它可能对那些人有所帮助。