build automation - Move a text file into target folder when compiling a Maven project -
i have slight different version of the question made recently. have maven project under netbeans 7.3, doesn't have build.xml
file configure building options, while there pom.xml
use import other libraries. now, have text file (let's textfile.txt
) stored in project folder in netbeans 7.3, e.g.
project folder textfile.txt src package package.subpackage myclass.java
when compile target
folder jar file put in, e.g.
project folder textfile.txt target classes generated-sources ....etc test-classes myproject.jar src package package.subpackage myclass.java
how can make file textfile.txt being copied under target folder when compile maven project?
a first way put files src/main/resources
folder devoted store complied resources, i.e. resources included jar file (e.g. images icons).
if need make config file distributed jar, separated it, must edit pom.xml
file. possible answer add following plugin between <plugins>
, </plugins>
tags.
<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-antrun-plugin</artifactid> <version>1.8</version> <executions> <execution> <phase>test</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>using env.test.properties</echo> <copy file="textfile.txt" tofile="${basedir}/target/textfile.txt"/> </tasks> </configuration> </execution> </executions> </plugin>
moreover, can read here can import resources "input" directory "output" directory inside target using dedicated plugin, e.g.:
<plugin> <artifactid>maven-resources-plugin</artifactid> <version>3.0.1</version> <executions> <execution> <id>copy-resources</id> <!-- here phase need --> <phase>validate</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputdirectory>${basedir}/target/output</outputdirectory> <resources> <resource> <directory>input</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin>
Comments
Post a Comment