首页 文章

在maven构建阶段复制文件

提问于
浏览
6

我的情况是:

  • 我有一个Maven项目,我在 /app/src/main/java 中有我的java类, /app/src/main/resources 中有我的资源,在 /app/src/main/webapp 有我的webapp文件

  • 我在 /common/script.js 有一个javascript文件

现在我想要的是在maven的构建阶段将javascript文件包含(复制)到war文件中 . 确切地说,我希望 script.js 落在war存档的 /js/ 目录中,就像它在开始构建之前放在 /app/src/main/webapp/js 中一样 .

我需要这个在许多网络应用程序之间共享一个版本的资源文件 .

亲切的问候,问:

3 回答

  • 5

    你可以做这样的事情,如here所述 .

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
              <webResources>
                <resource>
                  <!-- this is relative to the pom.xml directory -->
                  <directory>../common</directory>
                  <targetPath>/js</targetPath>
                </resource>
              </webResources>
            </configuration>
          </plugin>
        </plugins>
      </build>
      ...
    </project>
    
  • 1

    您可以使用mojo copy-resources复制不在默认maven布局中或未在build / resources元素中声明的资源 .

    校验

    "maven-resources-plugin"

  • 2

    您可以使用maven-resources plugin将文件复制到所需位置 . 在战争 Build 之前或之后

相关问题