【问题标题】:Maven assembly for .zip the project with only .jar and configuration files.zip 项目的 Maven 程序集,仅包含 .jar 和配置文件
【发布时间】:2018-07-23 14:11:46
【问题描述】:

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

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

我的问题是我的程序集没有使用我的配置文件,它确实使用了我的所有 jar,包括依赖项 jar。在我的项目结构和我的 POM 和程序集描述符下方。

这是我的项目结构:

组装-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>

【问题讨论】:

    标签: java maven jar maven-assembly-plugin


    【解决方案1】:

    当我只想压缩文件夹的一个子集时,我遇到了类似的问题。我的解决方案是直接使用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 配置文件中,以便仅在需要时启动它。

    【讨论】:

    • 好的,但是没有办法用 maven-assembly-plugin 做到这一点?
    • 当我想要更多的灵活性时,我已经放弃了这个插件。但我目前无法向您保证,maven-assembly-plugin 无法做到这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    • 2011-12-12
    相关资源
    最近更新 更多