Copy a file during maven build phase

元气小坏坏 提交于 2019-12-10 13:29:39

问题


My situation is:

  • I have a Maven project, I have my java classes in /app/src/main/java, my resources in /app/src/main/resources and my webapp files in /app/src/main/webapp
  • I have a javascript file in /common/script.js

Now what I want is to include (copy) the javascript file to the war file during the build phase of maven. To be precise, I want the script.js to land in /js/ directory of the war archive, just as it was placed in /app/src/main/webapp/js before starting the build.

I need this to share one version of resource files among many web-apps.

Kind regards, Q.


回答1:


You could do something like this, as documented 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>



回答2:


You can use the mojo copy-resources to copy resources which are not in the default maven layout or not declared in the build/resources element.

Check

"maven-resources-plugin"




回答3:


You can use maven-resources plugin to copy a file to the desired location. Before or after a war has been built



来源:https://stackoverflow.com/questions/8397357/copy-a-file-during-maven-build-phase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!