【问题标题】:maven custom assembly - how to copy external reference foldermaven自定义程序集 - 如何复制外部参考文件夹
【发布时间】:2011-12-17 14:18:15
【问题描述】:

我正在使用 maven(最新)构建一个简单的 Jar 项目
运行 ma​​ven package 时,我正确获取了目标目录下的 jar 文件,
我想自定义输出,以便 maven 将一些文件和依赖项复制到 jar 旁边的目标中。

当前文件夹结构为:

/  
-- resources  
-- src/main/java/com..(project sources)
-- src/main/assembly  (location of the assebmly.xml)

想要的目标目录结构是:

target
     |
      -- myJar1.0.jar         (the artiface)   
      -- resources            (from the root build folder)
      -- lib                  (all the dependancies)
            |
            -- anotherJar-1.0.jar
            -- anotherJar2-1.0.jar
            -- anotherJar3-1.0.jar


我在 apache 网站上阅读了custom assembly, 我将配置添加到 maven-assembly-plugin 并配置了 assembly.xml 但我必须做错事,我没有得到正确的输出,

这里是 assembly.xml

<assembly>
<id/>
<formats>
    <format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <outputDirectory>/lib</outputDirectory>
    </dependencySet>
</dependencySets>
<fileSets>
    <fileSet>
        <directory>target</directory>
        <outputDirectory>/lib</outputDirectory>
        <includes>
            <include>*.jar</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>resources</directory>
        <outputDirectory>/resources</outputDirectory>
        <includes>
            <include>*.*</include>
        </includes>
    </fileSet>
</fileSets>

目标目录包含具有依赖关系的库,但它位于具有工件名称的文件夹中, 资源目录根本没有被复制。

请指教 谢谢

【问题讨论】:

    标签: java jar maven-3


    【解决方案1】:

    我想你会想要 Maven resources plugin 来达到这个目的。

    【讨论】:

      【解决方案2】:

      根据设计,maven 程序集插件在目标的 子文件夹 中创建输出。这是为了避免与其中创建的其他工件(classestest-classes 等)混淆。

      至于没有被复制的资源,如果你想复制文件夹的全部内容,你可以省略&lt;includes&gt; 部分。第一个&lt;fileSet&gt; 部分也是多余的。

      更新了assembly.xml 以将项目工件放置在根目录中,将依赖库放置在 lib 中,并将资源放置在程序集文件夹的资源文件夹中...

      <assembly>
      <id/>
      <formats>
          <format>dir</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <dependencySets>
          <dependencySet>
              <outputDirectory>/lib</outputDirectory>
              <excludes>
                  <exclude>${project.groupId}:${project.artifactId}</exclude>
              </excludes>
          </dependencySet>
          <dependencySet>
              <outputDirectory>/</outputDirectory>
              <includes>
                  <include>${project.groupId}:${project.artifactId}</include>
              </includes>
          </dependencySet>
      </dependencySets>
      <fileSets>
          <fileSet>
              <directory>resources</directory>
              <outputDirectory>/resources</outputDirectory>>
          </fileSet>
      </fileSets>
      

      【讨论】:

      • 非常感谢您的帮助,它工作得很好,您认为是否可以告诉 maven 也将资源复制到 jar 中(所以 jar 中会有相同的资源文件夹和罐子外面)?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多