首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我尝试使用Maven程序集插件时,为什么要获得此错误消息?

当我尝试使用Maven程序集插件时,为什么要获得此错误消息?
EN

Stack Overflow用户
提问于 2015-07-20 13:24:10
回答 3查看 22.2K关注 0票数 6

我在Maven上是全新的,我正在教程中学习它。

在本教程中,我有以下pom.xml配置文件:

代码语言:javascript
复制
<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>

正如您在此配置文件中所看到的,程序集插件的使用声明如下:

代码语言:javascript
复制
        <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文件,该文件还包含项目的.jar依赖项。

因此,在Eclipse中,我选择了我的项目和运行为--> Maven构建,并在目标输入部分中编写了以下语句:

代码语言:javascript
复制
clean package assembly:single

它必须清理我的项目的目标目录,创建包,并在程序集插件上调用单一目标,该插件将jar依赖项放入我的项目的最终jar目标文件中。

问题是,这样做会在Eclipse控制台中获得以下错误消息:

代码语言:javascript
复制
.......................................................
.......................................................
.......................................................

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文件。

为什么我会得到这个错误?我遗漏了什么?我怎么才能修好它?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-07-20 13:59:43

您似乎没有正确地使用assembly插件。将插件条目更改为:

代码语言:javascript
复制
<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。这将在target目录中创建具有依赖关系的jar。您可以参考以下链接中给出的示例:https://maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html

票数 6
EN

Stack Overflow用户

发布于 2015-07-20 13:50:37

这就是我的maven POM在插件方面的样子。

代码语言:javascript
复制
<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>

我只能假设两件事:

  1. 您要么没有正确地格式化它,要么您正在使用的maven版本不支持您想要做的事情。
  2. 您可能没有正确设置bash配置文件并规定maven目录位于何处。此外,如果可能的话,尝试通过apache网站上显示的终端/命令提示符设置您的maven项目,并查看它是否有效。链接是:http://maven.apache.org/archetype/maven-archetype-plugin/examples/generate-batch.html

这是一个命令,用于为我的一个项目创建maven原型:

代码语言:javascript
复制
mvn -B archetype:generate \-DarchetypeGroupId=org.apache.maven.archetypes \-DgroupId=com.weather.mobile.ios.automation.tenday \-DartifactId=IphoneTenDayAutomation

groupID创建路径(将其视为包),而artificatID是类的名称。

票数 1
EN

Stack Overflow用户

发布于 2020-03-05 04:30:45

我对maven构建错误也有类似的问题。我尝试了更新快照选项上的复选框并进行了修复。如果背景中有旧的构建内容或者缓存之类的东西,它可能会对那些人有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31517727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档