2014-10-08 37 views
0

我有一个maven程序集插件的问题,我不明白为什么。不能依赖于maven程序集插件

我想创建一个可执行的jar文件,但在生成的jar文件中缺少一些东西。

实际上,生成的jar不包含实际上在pom(common-loggins)中引用的依赖项,而所有其他依赖项都存在于生成的jar中。

在jar的执行过程中,我在commons-logging类上得到了一个“NoClassDefError”。

我已经包含了一个简化的pom,因此您可以测试以查看问题。

父POM具有一个托管DEPENDENCY于commons-洛

<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/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>fr.home.ig.control</groupId> 
    <artifactId>control</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 

<artifactId>ig-bacth</artifactId> 
<name>ig-batch</name> 
<description>batch de l'application control</description> 
<packaging>jar</packaging> 

<dependencies> 
    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>1.1.3</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.5</version> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <mainClass>fr.home.ig.control.batch.BatchManager</mainClass> 
        </manifest> 
       </archive> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-jar-with-dependencies</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

+0

你有没有看着罐子的内容,以确保公共日志记录是否包含在内? – user944849 2014-10-08 16:20:05

回答

0

我不知道这么好这个插件,但你可能要考虑的可能性。

而不是汇编插件,使用阴影插件。 http://maven.apache.org/plugins/maven-shade-plugin/

  <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>2.2</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <createDependencyReducedPom>false</createDependencyReducedPom> 
          <filters> 
           <filter> 
            <artifact>*:*</artifact> 
            <excludes> 
             <exclude>META-INF/*.SF</exclude> 
             <exclude>META-INF/*.DSA</exclude> 
             <exclude>META-INF/*.RSA</exclude> 
             <exclude>.settings/**</exclude> 
             <exclude>*.classpath</exclude> 
             <exclude>*.project</exclude> 
             <exclude>*.txt</exclude> 
            </excludes> 
           </filter> 
          </filters> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

并创建一个完整的.exe包括全部或.exe其推出的所有一个.jar,使用launch4j插件https://github.com/lukaszlenart/launch4j-maven-plugin

  <plugin> 
       <groupId>com.akathist.maven.plugins.launch4j</groupId> 
       <artifactId>launch4j-maven-plugin</artifactId> 
       <version>1.5.2</version> 
       <executions> 
        <execution> 
         <id>l4j-gui</id> 
         <phase>package</phase> 
         <goals> 
          <goal>launch4j</goal> 
         </goals> 
         <configuration> 
          <headerType>gui</headerType> 
          <outfile>target/Project.exe</outfile> 
          <jar>target/${project.artifactId}-${project.version}.jar</jar> 
          <!-- if <dontWrapJar>true</dontWrapJar> change to this conf <jar>${project.artifactId}-${project.version}.jar</jar> --> 
          <dontWrapJar>false</dontWrapJar> 
          <errTitle>Error in launch4j plugin</errTitle> 
          <classPath> 
           <mainClass>path.Main</mainClass> 
          </classPath> 
          <icon>Project.ico</icon> 
          <jre> 
           <minVersion>1.5.0</minVersion> 
           <maxVersion>1.6.0</maxVersion> 
           <initialHeapSize>512</initialHeapSize> 
           <maxHeapSize>1024</maxHeapSize> 
          </jre> 
          <versionInfo> 
           <fileVersion>1.0.0.0</fileVersion> 
           <txtFileVersion>1.0.0.0</txtFileVersion> 
           <fileDescription>des</fileDescription> 
           <copyright>Copyright (c) 2014 </copyright> 
           <companyName>comp</companyName> 
           <productVersion>3.0.0.0</productVersion> 
           <txtProductVersion>${project.version}</txtProductVersion> 
           <productName>Project</productName> 
           <internalName>Project</internalName> 
           <originalFilename>Project.exe</originalFilename> 
          </versionInfo> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin>