Maven 3 assembly-plugin清单类路径位置

时间:2012-11-06 14:06:37

标签: maven-3 maven-assembly-plugin maven-dependency-plugin

我的pom.xml文件中有以下节点

http://maven.apache.org/xsd/maven-4.0.0.xsd“>     4.0.0

<groupId>com.company</groupId>
<artifactId>com.company</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>com.company</name>
<url>http://maven.apache.org</url>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.company.Thing</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>${project.build.directory}/lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-dependency-plugin
                                    </artifactId>
                                    <versionRange>
                                        [2.5.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>copy</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <exclusions>
            <exclusion>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

当我跑步时

mvn clean install target\java -jar com.company-...-jar-with-dependencies.jar 我得到了例外

线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / log4j / Logger

在eclipse中运行时,它运行正常。 target \ lib也包含log4j。另外我在哪里可以找到这个生成的清单文件?

1 个答案:

答案 0 :(得分:0)

您需要在子句中使用log4j,找到相应的version并添加它。程序集将自动查找并添加类文件。