0

我正在使用 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 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 中。

4

2 回答 2

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>
于 2013-01-22T05:55:51.240 回答
0
<fileset>...my classes... </fileset>

在程序集配置器/描述符中添加标签解决了这个问题。

感谢这条评论:

也许尝试为目标/类目录中的所有内容添加一个文件集?(不记得 POM 变量引用临时抱歉...) –查理1 月 22 日 7:21

于 2013-01-28T07:56:20.017 回答