2011-10-03 110 views
3

我有一个与很多依赖关系的maven项目。 我想使用程序集插件将所有内容都打包在依赖项中,但我不会将所有依赖关系的jar包解压缩成一团糟。我希望他们都进入lib文件夹,但我不知道如何添加类路径。 我POM:maven程序集创建jar与依赖和类路径

<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>test.com</groupId> 
    <artifactId>simple-weather</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>simple-weather</name> 
    <url>http://maven.apache.org</url> 

    <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>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 

        <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 

      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <classpathPrefix>lib/</classpathPrefix> 
         <mainClass>adi.com.weather.Main</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 

     </plugin> 

      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>make-assembly</id> 
         <phase>package</phase> 
         <goals> 
          <goal>attached</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <descriptors> 
         <descriptor>package.xml</descriptor> 
        </descriptors> 
       </configuration> 

      </plugin> 


     </plugins> 
    </build> 
</project> 

我的汇编文件

<?xml version="1.0" encoding="UTF-8"?> 
<assembly> 
    <id>test5</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
     <dependencySet> 
      <unpack>false</unpack> 
      <scope>runtime</scope> 
      <outputDirectory>lib</outputDirectory> 
     </dependencySet> 
    </dependencySets> 
    <fileSets> 
     <fileSet> 
      <directory>${project.build.outputDirectory}</directory> 
      <outputDirectory>/</outputDirectory> 

     </fileSet> 

    </fileSets> 
</assembly> 
+0

看起来你有正确的pom条目。哪里有问题?罐子不会进入lib文件夹?清单有不正确的罐子路径? – Raghuram

+0

清单中的classPath不起作用,但是我发现了一个soulution –

+3

不错的作品Adi Mor。你能否自己发布问题的答案,然后接受答案,以便我们能够解决这个问题?另外,如果他们解决了您的问题,则需要接受以前问题的答案。 – Zecas

回答

0

他可能重新配置自己的Maven的依赖插件:

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.10</version> 
      <executions> 
       <execution> 
        <id>copy</id> 
        <phase>package</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>${distDirectory}/lib</outputDirectory> 
         <includeScope>runtime</includeScope> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

现在,当你运行mvn package,所有的依赖罐子将会去target/lib(或任何你的distDirectory是)。

HTH

0

如果虽然你已经设置<addClasspath>true</addClasspath>,请确保您使用的是2.2版本或插件的更新的maven-JAR-插件未生成清单文件中的条目类路径。

版本2.1中的bug MJAR-83似乎阻止插件列出Class-Path中的依赖关系。

相关问题