【问题标题】:maven assembly plugin including jars dependencies and external filesmaven 程序集插件,包括 jars 依赖项和外部文件
【发布时间】:2014-11-04 21:51:45
【问题描述】:

我正在尝试使用 Assembly 插件来包含依赖项以及

这是我的汇编插件

<plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <executions>
                    <execution>
                        <id>create-executable-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>

                    </execution>
                </executions>

                <configuration>
                            <descriptorRefs>
                                <descriptorRef>
                                    jar-with-dependencies
                                </descriptorRef>  
                                   </descriptorRefs>
                                   <descriptors>
                                       <descriptor>src/assembly/assembly.xml</descriptor>
                                   </descriptors>
                            <archive>
                                <manifest>
                                   <mainClass>com.sarm.myproject.XMLParser.LPUnMarshaller</mainClass>
                                </manifest>
                            </archive>
                        </configuration>

            </plugin>

这是我的 assembly.xml 描述符,我将 id 设置为与 descritpor ref 相同,因为它正在为此描述符创建不同的 jar。所以我有两个描述符,一个是带有依赖关系的 jar 描述符 ref,一个是下面的描述符,在这种情况下,发生的事情是它创建了两个 jar,而第二个 jar 覆盖了前一个 jar。怎么可能将这两个包含在同一个 jar 中。

<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>jar-with-dependencies</id>
  <formats>
    <format>jar</format>
  </formats>


    <fileSets>
    <fileSet>
      <directory>${basedir}</directory>
      <includes>
        <include>*.xml</include>
      </includes>

  <excludes>
        <exclude>30000dests.xml</exclude>

      </excludes>

    </fileSet>
    <fileSet>
      <directory>${basedir}/test</directory>
      <includes>
        <include>*.xml</include>
      </includes>

    </fileSet>
  </fileSets>
</assembly>

编辑:我尝试了一些其他方法,并且我发现如果我使用 assembly.xml 作为描述符,则会在创建的任何其他默认 jar 旁边创建一个新 jar。所以我最终得到了两个罐子。默认 jar 是一个可执行文件,就像配置了 jar 插件一样。即使程序集插件配置为具有带有我的主类名称的 manifest.mf,通过 assmbly.xml 创建的 jar 也是不可执行的,并且有一个包含我的项目名称的文件夹,其中包含可执行 jar。

我使用 mvn clean install 来构建我的项目和 jar 文件。

【问题讨论】:

    标签: java maven jar


    【解决方案1】:

    您应该创建两个生成两个 jar 的模块。通常,maven 会为每个模块生成一个 jar 文件,并将模块名称作为 jar 名称。 Maven 建议每个模块都有一个输出工件。

    如果您担心重复代码。您可以通过拥有父 pom 来继承相关的东西。

    【讨论】:

    • 感谢您的回复。这个想法是只有一个罐子。具有依赖项和外部文件。两个罐子,一个有库,一个只有外部,第二个甚至没有课程,它们不会对我有太大帮助。我只会运行jar。此外,罐子以爆炸形式出现。如果我将 assembly.xml 与依赖集一起使用,那么我可以拥有 jar,但是我错过了代码。为什么编译后的类没有与用 assembly.xml 创建的 jar 打包。我真的很喜欢使用 assembly.xml 的想法,它非常灵活。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 2010-12-29
    • 2016-05-14
    • 2015-03-29
    • 1970-01-01
    • 2016-02-23
    相关资源
    最近更新 更多