2014-10-08 38 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>