java - .zip 项目的 Maven 程序集,仅包含 .jar 和配置文件

标签 java maven jar maven-assembly-plugin

我正在尝试使用程序集 Maven 插件将我的项目与我的项目 .jar 和一些配置文件一起压缩。

我想要模块 admin batch_base_to_base batch_engine batch_generic 中的 JAR 和一些文件到 misc

我的问题是我的程序集不获取我的配置文件,并且它确实获取我的所有 jar,包括依赖项 jar。下面是我的项目结构以及 POM 和程序集描述符。

这是我的项目结构:

Project structure

程序集-dr3.xml:

<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>bin</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>


  <moduleSets>
    <moduleSet>
      <useAllReactorProjects>true</useAllReactorProjects>
      <includes>
        <include>com.mycompany.dr3:batch_engine</include>
        <!-- for test but it still includes below modules
        <include>com.mycompany.dr3:admin</include>
        <include>com.mycompany.dr3:batch_generic</include>
        <include>com.mycompany.dr3:batch_base_to_base</include>
        -->
      </includes>
      <sources>
          <fileSets>
            <fileSet>
              <directory>${project.basedir}/misc</directory>
              <includes>
                <include>configuration.json</include>
                <include>environment_placeholders.json</include>
              </includes>
            </fileSet>
          </fileSets>
      </sources>
      <binaries>
        <outputDirectory>modules/maven-assembly-plugin</outputDirectory>
        <unpack>false</unpack>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
        <groupId>com.mycompany.dr3</groupId>
        <artifactId>dr3</artifactId>
        <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>dr3-package</artifactId>
  <packaging>pom</packaging>


  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.3</version>
        <configuration>
          <descriptor>assembly-dr3.xml</descriptor>
        </configuration>
        <executions>
          <execution>
            <id>create-archive</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

最佳答案

当我只想压缩文件夹的子集时,我遇到了类似的问题。我的解决方案是直接使用 maven-antrun-plugin 来完成您想要的操作。类似于:

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
    <version>${maven-antrun-plugin.version}</version>
      <executions>
        <execution>
          <phase>install</phase>
           <configuration>
             <target>
           <!-- delete previous old tmp folder -->
           <delete dir="${temporal-folder}" failonerror="false" includeemptydirs="true" />
           <!-- create tmp folder -->
           <mkdir dir="${temporal-folder}" />
           <!-- copy some stuff -->
           <copy todir="${temporal-folder}/somestuff/" overwrite="true">
              <fileset dir="./folder-i-want-to-copy" includes="**/*" />
           </copy>
           <!-- copy more stuff -->
           <copy todir="${temporal-folder}/otherstuff/" overwrite="true">
              <fileset dir="./other-source" includes="**/*" />
           </copy>
           <!-- create the final file -->
           <zip basedir="${temporal-folder}/" destfile="../${destination-file}-${project.version}.zip" />
        </target>
     </configuration>
     <goals>
        <goal>run</goal>
     </goals>
  </execution>
 </executions>
</plugin>

我通常将此插件放在 Maven 配置文件中,仅在需要时启动它。

关于java - .zip 项目的 Maven 程序集,仅包含 .jar 和配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48762882/

相关文章:

java - 程序中s2+=s1.charAt(i)是什么意思

maven - org.datanucleus.exceptions.NucleusUserException : Error : Could not find API definition for name "JDO"

java - 我如何找出 Eclipse 陷入无限构建周期的原因?

java - 是什么原因导致 java.lang.IncompleteClassChangeError?

java - 执行jar文件时出错

java - C、C++中有没有办法根据我们的需要控制内存、寄存器?

java - 制作多个maven镜像仓库

java - 添加 tomcat-catalina 依赖项时 Tomcat 服务器没有响应

java - 运行 jar 时出现 FileNotFoundException

java - Android:加载照片时出错