I'm currently working on an existing project which has a pom.xml file with the following:
<resources>
<resource>
<filtering>false</filtering>
<directory>src</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
I have in the base path a directory called properties which contains properties files. I want to copy when packaging all the properties files contains under properties/ in my src directory (otherwise the program will crash due to missing configuration files).
So my question is:
How can i, with Maven include resource files that are not located under src directory?
I try this one but it doesn't seem to work:
<resources>
<resource>
<filtering>false</filtering>
<directory>src</directory>
<includes>
<include>**/*.properties</include>
<include>../properties/**</include>
</includes>
</resource>
</resources>
Thank's for your help.
The maven targets are located in your project config/ folder.
Target. The target folder is the maven default output folder. When a project is build or packaged, all the content of the sources, resources and web files will be put inside of it, it will be used for construct the artifacts and for run tests. You can delete all the target folder content with mvn clean command.
Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder.
To include a resource, we only need to add an <includes> element. And to exclude a resource, we only need to add an <excludes> element. For example, if we want to include all text and RTF files under our src/my-resources directory and in all its subdirectories, we can do the following: <project>
If your file structure is like this: Standard Directory Layout
Then you dont have to add the resources elemt.
Maven copies by default all the files and folders that are located in your /src/main/resources folder to your build folder and locates them in the root of your compiled classpath files.
if you have for example a file called configuration.properties located in /src/main/resources/configuration.properties
then when running mvn clean compile
this file will be copied to your /target/classes/configuration.properties
So if you remove that part the files will be located where u want them
<resource>
<filtering>false</filtering>
<directory>src</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
By migrating of projects from ant to maven without changing project structure set your sourceDirectory testSourceDirectory in the build and use the maven-resource-plugin as folowing take care in wich phase you execute the goals.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources01</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/src</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resources02</id>
<phase>verify</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/build/lib</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/target/</directory>
<include>*.jar</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With