我如何让maven构建发行版?

我如何让maven构建发行版?,maven,Maven,我的意思是,我希望我的所有依赖项都以jar的形式放入一个zip文件中 这是我的pom: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&

我的意思是,我希望我的所有依赖项都以jar的形式放入一个zip文件中

这是我的pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mkyong.hashing</groupId>
  <artifactId>java-project</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>java-project</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!-- Dependency for hashing -->
    <!-- https://search.maven.org/artifact/commons-codec/commons-codec/1.11/jar -->
    <dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.11</version>
    </dependency>
    <dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.9.0</version>
</dependency>

  </dependencies>
  <build>
    <plugins>

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                <mainClass>com.mkyong.hashing.App</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
        </execution>
      </executions>

        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>4.12</version>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/lib/</outputDirectory>
              <!--<destFileName>optional-new-name.jar</destFileName>-->
            </artifactItem>
          </artifactItems>
          <artifactItems>
            <artifactItem>
              <groupId>commons-codec</groupId>
              <artifactId>commons-codec</artifactId>
              <version>1.11</version>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/lib/</outputDirectory>
              <!--<destFileName>optional-new-name.jar</destFileName>-->
            </artifactItem>
          </artifactItems>
          <artifactItems>
            <artifactItem>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.9.0</version>

              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/lib/</outputDirectory>
              <!--<destFileName>optional-new-name.jar</destFileName>-->
            </artifactItem>
          </artifactItems>
          <artifactItems>
            <artifactItem>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>4.12</version>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/lib/</outputDirectory>
              <!--<destFileName>optional-new-name.jar</destFileName>-->
            </artifactItem>
          </artifactItems>
    </configuration>

    <!--<executions>
        <execution>
            <id>copy</id>
            <phase>install</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>
                  ${project.build.directory}/lib
                </outputDirectory>
            </configuration>
        </execution>
    </executions>-->
</plugin>



      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
            <!--    <excludes>
                  <exclude>classworlds:classworlds</exclude>
                  <exclude>junit:junit</exclude>
                  <exclude>jmock:*</exclude>
                  <exclude>*:xml-apis</exclude>
                  <exclude>org.apache.maven:lib:tests</exclude>
                  <exclude>log4j:log4j:jar:</exclude>
                </excludes>-->
              </artifactSet>
            </configuration>
          </execution>
        </executions>
</plugin><plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.3</version>
        <configuration>
          <!-- <descriptor>src/assembly/dep.xml</descriptor>  -->

          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>com.mkyong.hashing</mainClass>
            </manifest>
          </archive>
        </configuration>

        <executions>
          <execution>
            <id>create-archive</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
在.com/xEeYGTtB

中,在src/main/assembly中创建一个XML文件。让我们称之为zip.xml


最后,使用mvn clean install构建代码,如果构建成功,您将在目标目录中看到zip文件。

可能您正在寻找的是一个胖jar,请不要发布完整的代码,而只发布相关部分。你的问题应该显示出你为解决问题所做的努力。很抱歉,我不想遗漏任何东西,我真的不知道我在做什么。要将所有文件放入zip文件,最好的选择是通过maven assembly插件。。。。
<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>zip</id>
    <includeBaseDirectory>true</includeBaseDirectory>

    <formats>
        <format>zip</format>
    </formats>
    <files>
        <file>
            <source> ${project.build.directory}/${project.artifactId}-${project.version}.jar</source>
            <outputDirectory>/</outputDirectory>
        </file>
    </files>
    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
            <excludes>
                <exclude>${project.groupId}:${project.artifactId}:jar:*</exclude>
            </excludes>
        </dependencySet>
    </dependencySets>
</assembly>
 <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-assembly-plugin</artifactId>
   <executions>
      <execution>
         <phase>package</phase>
         <goals>
            <goal>single</goal>
         </goals>
         <configuration>
            <appendAssemblyId>false</appendAssemblyId>
            <descriptors>
               <descriptor>src/main/assembly/zip.xml</descriptor>
            </descriptors>
         </configuration>
      </execution>
   </executions>
</plugin>