Maven:制作具有依赖关系的罐子:书中的示例不起作用 [英] Maven: Making Jars With Dependencies: Example From Book Doesn't Work

查看:89
本文介绍了Maven:制作具有依赖关系的罐子:书中的示例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Maven的一个完整的初学者.我一直在关注《 示例学习》 .在6.13节中,作者演示了如何使用命令中包含的依赖项来制作JAR.

I am a complete beginner with Maven. I've been following the book Maven By Example. In the section 6.13 the author demonstrates making a JAR with the dependencies included via the command

mvn install assembly assembly

我遵循了第6章中的示例,只是我跳过了单元测试部分.我回过头来确保没有跳过步骤.但是,当我尝试上述命令时,得到了以下错误输出:

I followed the example in chapter 6, except I skipped the parts with unit testing. I went back through them to make sure I didn't skip a step. However when I tried the above command I got this error output:

[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ simple-weather ---
[INFO]
[INFO] <<< maven-assembly-plugin:2.2-beta-5:assembly (default-cli) @ simple-weather <<<
[INFO]
[INFO] --- maven-assembly-plugin:2.2-beta-5:assembly (default-cli) @ simple-weather ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.094s
[INFO] Finished at: Wed Mar 21 15:53:03 EDT 2012
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:assembly (default-cli) on project simple-weather: Error readi
ng assemblies: No assembly descriptors found. -> [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
C:\home\Projects\simple-weather>

问题出在插件部分的jar-with-dependencies描述符中.我在谷歌上搜索了一下,但是没有找到与本书不同的方法.因此,我很想知道我要去哪里哪里.

The problem is with the jar-with-dependencies descriptor in the plugins section. I googled around a bit, but didn't find a different way to do it from the book. So, I would be interested to know where I am going wrong.

这是我的pom.xml:

Here is my 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>org.sonatype.mavenbook.custom</groupId>
    <artifactId>simple-weather</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>simple-weather</name>
    <url>http://www.sonatype.com</url>


    <licenses>
        <license>
            <name>Apache 2</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>

    <organization>
        <name>Sonatype</name>
        <url>http://www.sonatype.com</url>
    </organization>

    <developers>
        <developer>
            <id>jason</id>
            <name>Jason Van Zyl</name>
            <email>jason@maven.org</email>
            <url>http://www.sonatype.com</url>
            <organization>Sonatype</organization>
            <organizationUrl>http://www.sonatype.com</organizationUrl>
            <roles>
                <role>developer</role>
            </roles>
            <timezone>-6</timezone>
        </developer>
    </developers>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>jaxen</groupId>
            <artifactId>jaxen</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.5</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>






</project>

非常感谢您提供任何线索.

Thanks much in advance for any clues.

推荐答案

问题是您为编译插件而不是程序集插件配置了描述符引用.

The problem is you have your descriptor refs configured for the compile plugin instead of the assembly plugin.

将此添加到您的/build/plugins部分

Add this to your /build/plugins section

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
</plugin>

并从编译器插件配置中删除以下内容,因为它没有执行任何操作.

and remove the below from your compiler plugin config as it is not doing anything.

<descriptorRefs>
  <descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>

这篇关于Maven:制作具有依赖关系的罐子:书中的示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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