是否将Maven Assesmnly插件的jar-with-dependencies descriptorRef的内容记录为示例汇编描述符文件?

时间:2014-01-23 14:19:06

标签: java maven jar

以下参见How can I create an executable jar with dependencies using Maven?显示了如何使用Maven插件创建可执行jar。

  <build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>

但是我希望排除我POM中的一些依赖项。我想要做的就是添加

   <dependencySets>
    <dependencySet>
        <useStrictFiltering>true</useStrictFiltering>
        <scope>compile</scope>
        <excludes>
            <exclude>com.excluded:artifact</exclude>
        </excludes>
    </dependencySet>
</dependencySets>

以上但我不能,因为我需要在单独的汇编描述符中添加它。我想要做的是与jar-with-dependencies完全相同但排除。是否存在描述等效汇编描述符文件的位置,以便我可以编辑它?有没有办法'继承'jar-with-dependencies并添加我的排除?

2 个答案:

答案 0 :(得分:0)

有关jar-with-depedencies的等效内容,请参阅The Maven Documentation on pre defined descriptors

所以我可以改变我用来构建'超级jar'的POM,如下所示;

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>my.Main</mainClass>
                    </manifest>
                </archive>
                <descriptors>
                    <descriptor>src/main/assembly/assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <!-- Uncomment this for automatic creation of the Complete jar
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
             -->
        </plugin>

在目录src / main / assembly / assembly.xml中,我可以将以下内容与jar-with-dependencies描述符与我的排除项基本相同;

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
      <!-- TODO: a jarjar format would be better -->
      <id>jar-with-dependencies</id>
      <formats>
        <format>jar</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <dependencySets>
        <dependencySet>
          <outputDirectory>/</outputDirectory>
          <useProjectArtifact>true</useProjectArtifact>
          <unpack>true</unpack>
          <scope>runtime</scope>
            <excludes>
                <exclude>com.local.depedency:artifact_id</exclude>
                <exclude>transitive.depedency.so.way.down:artifact_id</exclude>
            </excludes>
        </dependencySet>
      </dependencySets>
</assembly>

答案 1 :(得分:0)

我认为你可以使用范围“编译”

<dependency>
    <groupId>com.xxxx</groupId>
    <artifactId>xxxxxx</artifactId>
    <version>3.x</version>
    <scope>compile</scope>
</dependency>