Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 2 如何在Maven2中将模块jar合并到单个jar中?_Maven 2 - Fatal编程技术网

Maven 2 如何在Maven2中将模块jar合并到单个jar中?

Maven 2 如何在Maven2中将模块jar合并到单个jar中?,maven-2,Maven 2,我有一个带有几个jar模块的maven2项目,构建该项目将获得modules/XYZ/target/XYZ-x.x.jar目录中每个模块的.jar存档 现在,如果我的项目p是p-p.q.r版本,我想生成一个包含所有子模块的jarp-p.q.r-all.jar,我该怎么做 如果您的jar是一个库,您希望其他开发人员通过maven下载和使用,那么这取决于您将如何发布它。您应该在项目pom中指定这些 如果您正试图将某些东西发送给一个只想获取二进制文件并使用您的项目的最终用户,那么您可以尝试使用插件来打

我有一个带有几个jar模块的maven2项目,构建该项目将获得modules/XYZ/target/XYZ-x.x.jar目录中每个模块的.jar存档


现在,如果我的项目p是p-p.q.r版本,我想生成一个包含所有子模块的jarp-p.q.r-all.jar,我该怎么做

如果您的jar是一个库,您希望其他开发人员通过maven下载和使用,那么这取决于您将如何发布它。您应该在项目pom中指定这些


如果您正试图将某些东西发送给一个只想获取二进制文件并使用您的项目的最终用户,那么您可以尝试使用插件来打包您的项目。有了这个插件,您可以将jar与其依赖项一起打包。它不会将所有内容都放在一个jar文件中,但假设您正确配置了用户的类路径,这并不重要。

您想要实现的就是uber jar。该模块必须依赖于要打包到一个jar中的所有其他子模块。如果您创建另一个子模块来生成所需的工件,则可以在reactor中构建它及其所有依赖项,但如果它是一个单独的项目,则必须安装所有uber jar依赖项

| parent
| -- submodule1
...
| -- submoduleN
| -- uberjarSubmodule
Uber jar可以通过以下方式完成:

  • -在您的情况下,您必须记住从模块中排除可传递依赖项

    <project>
    ...
    <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>
              <artifactSet>
                <excludes>
                  <exclude>classworlds:classworlds</exclude>
                  <exclude>junit:junit</exclude>
                  <exclude>jmock:jmock</exclude>
                  <exclude>xml-apis:xml-apis</exclude>
                </excludes>
              </artifactSet>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
    </build>
    ...
    </project>
    
    
    ...
    org.apache.maven.plugins
    -在这个问题上,你会找到一个详细的答案