Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/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
Java 如何告诉Maven将所有依赖项重新打包到一个jar文件中_Java_Maven_Jar_Pom.xml - Fatal编程技术网

Java 如何告诉Maven将所有依赖项重新打包到一个jar文件中

Java 如何告诉Maven将所有依赖项重新打包到一个jar文件中,java,maven,jar,pom.xml,Java,Maven,Jar,Pom.xml,给定一个包含依赖项列表的pom.xml文件,是否有Maven命令将所有这些jar捆绑到一个大jar中我不想在构建中包含我的.class文件-我只想在构建中包含库.class/jar文件-有什么方法可以做到这一点吗 我看到了这个插件: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifac

给定一个包含依赖项列表的pom.xml文件,是否有Maven命令将所有这些jar捆绑到一个大jar中我不想在构建中包含我的.class文件-我只想在构建中包含库.class/jar文件-有什么方法可以做到这一点吗

我看到了这个插件:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/Crunchify/lib</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>

但是,当我使用pom.xml中的
maven汇编插件运行
mvn clean package
时,我没有看到任何新的jar文件。

Wit
jar与依赖项
single~package
,你陷入了汇编的一个“陷阱”(在包(未完成)之前没有任何东西需要汇编)

但结合这两个插件,这将起作用:

/pom.xml …将为您提供:

/target/${build.finalName}-big-big-jar.jar
…文件,包含所有暂时依赖项,而不包含.jar/类。

jar和
single~package
,您陷入了程序集的一个“陷阱”(在包(未完成)之前没有任何程序集)

但结合这两个插件,这将起作用:

/pom.xml …将为您提供:

/target/${build.finalName}-big-big-jar.jar
..文件,包含所有没有.jar/类的临时依赖项。

这是类似的:maven shade插件()是一个不错的选择。它可以处理组合JAR时出现的所有奇怪情况(例如,合并元数据)。@Rob Thank,你能举一个只打包依赖项而不打包用户/项目类的例子吗?为了帮助理解什么是好的解决方案,你能解释一下为什么不想在结果JAR中打包类吗?
${project.build.directory}
通常是
target
文件夹…这是类似的:maven shade plugin()是一种方法。它可以处理组合JAR时出现的所有奇怪情况(例如,合并元数据)@Rob谢谢,你能举一个只打包依赖项而不打包用户/项目类的例子吗?为了帮助理解什么是一个好的解决方案,你能解释一下为什么你不想把你的类放在结果JAR中吗?
${project.build.directory}
通常是
目标
文件夹。。。
     <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.1</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
<project>
   ...
    <!-- many many dependencies -->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/assembly/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>copy-deps</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  <id>big-big-jar</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}/dependency</directory>
      <outputDirectory />
      <includes>
        <!-- attention: maybe you need more ... zip, tz.gz.bz. -->
        <include>*.jar</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>
mvn clean package
...
BUILD SUCCESS