Copy the file during the maven build phase

My situation:

  • I have a Maven project, I have 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 I want to include (copy) the javascript file into the war file during the maven build phase. To be precise, I want script.js to land in the / js / directory of the military archive, just like it was placed in the / app / src / main / webapp / js folder before starting the build.

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

Regards, Question.

+6
source share
3 answers

You can do something like this as described 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> 
+5
source

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

Check out

"maven-resources-plugin"

+2
source

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

+1
source

Source: https://habr.com/ru/post/903174/


All Articles