我遇到了maven程序集插件的问题,我无法理解为什么。
我希望创建一个可执行jar,但生成的jar中缺少一些东西。
实际上,生成的jar不包含pom(common-loggins)中实际引用的依赖项,而所有其他依赖项都存在于生成的jar中。
执行jar时,我在commons-logging类上得到一个“NoClassDefError”。
我已经包含了一个简化的pom,因此您可以进行测试以查看问题。
父母POM在commons-loggin上具有管理的依赖性
<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 :(得分:0)
我不太了解这个插件,但你有可能想要考虑。
使用shade插件代替程序集插件。 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,包括全部启动.jar的全部或.exe,请使用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>