我正在使用maven来构建我的项目。我想创建包含一些依赖项的程序集jar,所以我编写了自定义程序集描述符。
的pom.xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.guavus.exporter.Exporter</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>/Users/archit.thakur/Documents/Code_dev_cdn_mapreduce/exporter/src/main/assembly/configurator.xml</descriptor>
<!-- <descriptorRef>jar-with-dependencies</descriptorRef> -->
</descriptors>
<finalName>Exporter-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
ASSEMBLY DESCRIPTOR:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>dep</id>
<formats>
<format>jar</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>${project.artifactId}</outputDirectory>
<unpack>true</unpack>
<useProjectArtifact>true</useProjectArtifact>
<includes>
<include>log4j:log4j</include>
<include>org.slf4j:slf4j-api</include>
<include>ch.qos.logback:logback-access</include>
<include>ch.qos.logback:logback-classic</include>
<include>ch.qos.logback:logback-core</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
问题是,现在创建jar只有依赖jar。而不是从我的代码中制作jar并将其包含在最终的jar中。
答案 0 :(得分:1)
尝试使用Shade插件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.app.MyMainClass</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>org.eclipse.swt.win32.win32:x86</artifact>
<excludes>
<exclude>META-INF/eclipse.inf</exclude>
<exclude>META-INF/ECLIPSE.RSA</exclude>
<exclude>META-INF/ECLIPSE.SF</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
答案 1 :(得分:0)
<fileset>...my classes... </fileset>
在程序集配置程序/描述符中添加标记解决了这个问题。
感谢此评论:
也许尝试为target / classes目录中的所有内容添加fileSet? (不记得POM变量引用随便抱歉......) - Charlie 1月22日7:21