java - 如何使用 Maven 构建将常规文件夹添加到我的存储库?

标签 java maven pom.xml maven-assembly-plugin

现在,如果我将项目作为“Maven 安装”运行,我的 Java Maven 构建会创建一个 war 文件和一个 zip 文件,它们都位于同一目录位置。

如何让此构建将常规文件夹添加到此目录位置,并将 zip 文件放入该文件夹中?

更多信息

我尝试使用 maven-assemble-plugin。在repository.xml 中,我指定将哪些文件放入我的zip 中。这些文件位于 ${project.basedir}/files 中。我尝试将文件放入“extrafolder”中,以便它们位于 ${project.basedir}/files/extrafolder 中,希望这个额外的文件夹位于我的本地存储库中,但 Maven 忽略了该文件夹,仍然将 war 和 zip 都放在其中在同一个存储库中。

这是我的 POM 中的插件:

<project>
  [...]
  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <descriptors>
            <descriptor>src/assembly/repository.xml</descriptor>
          </descriptors>
        </configuration>
      </plugin>
   [...]
</project>

这是repository.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>repository</id>
  <formats>
    <format>tar</format>
  </formats>
<includeBaseDirectory>false</includeBaseDirectory> 
   <fileSets>
         <fileSet>  
           <directory>${project.basedir}/files</directory>
            <outputDirectory>/</outputDirectory>
             <filtered>true</filtered>
            <includes>
                <include>**/*.*</include> 
            </includes>           
        </fileSet>         
    </fileSets>  
</assembly>

最佳答案

如果需要,您应该将outputDirectory 配置为额外文件夹。示例如下:

   <fileSets>
     <fileSet>  
       <directory>${project.basedir}/files</directory>
        <outputDirectory>extrafolder</outputDirectory>
         <filtered>true</filtered>
        <includes>
            <include>**/*.*</include> 
        </includes>           
    </fileSet>         
</fileSets>  

配置插件将 zip 文件放入特定文件夹,如下所示:

      <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
      <outputDirectory>extrafolder</outputDirectory>
      <descriptors>
        <descriptor>src/assembly/repository.xml</descriptor>
      </descriptors>
    </configuration>
  </plugin>

在此处查找更多详细信息:https://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html#outputDirectory

关于java - 如何使用 Maven 构建将常规文件夹添加到我的存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60105172/

相关文章:

java - 将独立jar导入本地maven存储库

java - 如何使用maven依赖生成xml报告?

maven - 即使我所有的测试都通过了,我还是看到了 surefire 错误的错误,没有与 surefire 插件相关的答案帮助我

java - fragment recyclerview 不同的 View 类型不起作用

java - 如何将 CaretEvent.getDot() 转换为直角坐标?

java - Hadoop单节点集群

java - 在jsp中包含一个cpp文件

java - maven 编译时连接被拒绝

java - 添加 ContentNegotiatingViewResolver 时出现内部服务器错误

android - 使用多个 `POM file is invalid`时如何修复 `exclude`?