在 Maven 中创建 zip,并在 jar 旁边添加其他文件

2024-01-25

我唯一的 Maven 经验是包含其他库,因此我需要一个非常基本的解释来说明如何使用 Eclipse 在 Maven 中实现某些功能。

我想定期创建我的罐子。然后我想再获取 3 个文件,并将所有文件放在 1 个 zip 文件中。我的 zip 内容应如下所示:

A.jar
B.txt
C.txt
D.bat

我知道我必须在我的生活中插入某些目标pom.xml文件。我已经在 Stack Overflow 上看到了帖子(即here https://stackoverflow.com/questions/5717183/create-a-zip-with-all-dependencies-with-maven)关于类似的主题。我还尝试了 Maven 文档,例如here http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html。我是否已经需要任何 Maven 插件或者仍然是 Maven 核心的东西?

但我的技能还不足以为我的案件转移这些信息。


+ project 
    + src/main/java
    + src/main/resources
    + src/main/config
            +B.txt
            +C.txt
            +D.bat
    + src/main/assembly
            +bin.xml
    +pom.xml

bin.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>bin</id>
  <baseDirectory>/</baseDirectory>
  <formats>
    <format>zip</format>
  </formats>
   <fileSets>
    <fileSet>
      <directory>${project.basedir}/src/main/config</directory>
      <outputDirectory>/</outputDirectory> 
    </fileSet>
    <fileSet>
      <directory>${project.build.directory}</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>*.jar</include>
      </includes>
    </fileSet> 
  </fileSets>
</assembly>

poml.xml

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <descriptors>
            <descriptor>src/main/assembly/bin.xml</descriptor>
        </descriptors>
        <appendAssemblyId>false</appendAssemblyId>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- append to the packaging phase. -->
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Output: mvn清理包

+ artifactId-version.zip
    + B.txt
    +C.txt
    +D.txt
    +artifactId-version.jar

没有在 src/main/resources 中添加 B.txt、C.txt、D.bat,因为将它们放在 CLASSSPATH 中并不好

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Maven 中创建 zip,并在 jar 旁边添加其他文件 的相关文章

随机推荐