2012-02-11 32 views
4

我试图使用Maven创建包含在单独的目录的依赖可执行的JAR文件的依赖性。我已经看到很多关于创建“超级巨人”的问题 - 我不想那么做。我想是有复制到像这样一个“lib”目录的depenedencies(和JAR MANIFEST.MF文件与ClassPath条目指向它们):如何建立与Maven运行的JAR包含在一个单独的“LIB”文件夹(不是超级JAR)

/myApp 
    myApp.SNAPSHOT-1.0.jar 
    /lib 
    hibernate.jar 
    log4j.jar 
    ... 

作为额外的奖励,如果我这将是很好可以复制/src/main/resources/*/myApp/conf,然后拉上拉链,整个/myApp目录到myApp.zip为好。

编辑:我使用maven的依赖,插件和Maven的资源,插件和Maven的罐子的插件。这是我包括我的pom.xml(其复制运行时依赖于/目标/ release/lib目录,这样我可以拉上/目标/释放,它已经准备好去):

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>copy-dependencies</id> 
      <phase>package</phase> 
      <goals> 
       <goal>copy-dependencies</goal> 
      </goals> 
      <configuration> 
       <includeScope>runtime</includeScope> 
       <outputDirectory> 
        ${project.build.directory}/release/lib 
       </outputDirectory> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-resources-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>copy-resources</id> 
     <!-- here the phase you need --> 
     <phase>package</phase> 
     <goals> 
      <goal>copy-resources</goal> 
     </goals> 
     <configuration> 
      <outputDirectory>${project.build.directory}/release</outputDirectory> 
      <resources>   
      <resource> 
       <directory>src/main/config</directory> 
       <filtering>true</filtering> 
      </resource> 
      </resources>    
     </configuration>    
     </execution> 
    </executions> 
</plugin> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>jar</goal> 
      </goals> 
      <configuration> 
       <outputDirectory> 
        ${project.build.directory}/release/lib 
       </outputDirectory> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

回答

5

Maven的依赖插件有一个复制依赖目标,应该做你想做的。

mvn dependency:copy-dependencies 

有关可用选项,请参阅here。即“输出目录”的依赖关系复制到/ lib目录

+0

嗯,好我不知道那根本。但是,我将如何更新我的jar的清单文件来为类路径使用该位置? – 2012-02-11 23:08:18

+0

什么[清单定制(http://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html)?当然,使用属性或maven变量。 – 2012-02-12 22:02:00

+0

@dma_k,嗯,可能的工作,我会考虑这样做。 – 2012-02-14 06:50:29

相关问题