1

I am trying to copy property file in my project which is at the same level of pom.xml to a specific folder in tomcat. I am using the maven-resources-plugin. My maven version is apache-maven-3.8.6

Following is the folder structure of where the duplicateReport.properties file is present

enter image description here

Here is the snippet in pom.xml

 <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-resources-plugin</artifactId>
                            <version>2.4.2</version>
                 
                                            <configuration>
                                                    <overwrite>false</overwrite>
                                                    <outputDirectory>${env.CATALINA_HOME}/warfiles</outputDirectory>
                                                    <resources>
                                                            <resource>
                                                                    <directory>${project.basedir}</directory>
                                                                    <filtering>false</filtering>
                                                                     <includes>
                                                                            <include>**/duplicateReport.properties</include>
                                                                    </includes>
                                                            </resource>
                                                    </resources>
                                            </configuration>

                    </plugin>

In the environment variable (system variables) have set the CATALINA_HOME a below

CATALINA_HOME C:\Users\d_avi\eclipse-workspace\tomcat9

But when i try to access the variable in the output directory it is not able to resolve the catalina path, instead it creates the path in my project base directory

<outputDirectory>${env.CATALINA_HOME}/warfiles</outputDirectory>

This is how it creates

C:\codebase\combinedrepo${env.CATALINA_HOME}\warfiles And in this location it places the duplicateReport.properties file.

Following are the visual representation of the folder structure created.

enter image description here enter image description here enter image description here

Also when the absolute path is given in the output directory as below, it copies the file

<outputDirectory>C:\Users\d_avi\eclipse-workspace\tomcat9\warfiles</outputDirectory>

Also i have gone through this in stackoverflow Maven: copy file from workspace to folder which is outside of target

Also this How to refer environment variable in POM.xml?

Any help or suggestions please, what is that i am missing here.

Avinash Reddy
  • 2,204
  • 3
  • 25
  • 44
  • resources should be located in `src/main/resources` ... – khmarbaise Aug 18 '22 at 14:54
  • @khmarbaise if the property file is not in src/main/resources, can it not be copied to the specified destination ? – Avinash Reddy Aug 18 '22 at 14:56
  • What kind of specify location? resources are by default in `target/classes` ... or in case of a war packaging `WEB-INF/classes`... ? – khmarbaise Aug 18 '22 at 18:12
  • @khmarbaise Specific location meaning, i am trying to put my properties file in Tomcat folder. The properties files is at the same location of pom.xml. If you can see the outputDirectory – Avinash Reddy Aug 19 '22 at 02:14
  • First you should deploy a WAR file to tomcat and do not try to use Maven as a deployment tool there other tools for such job..furthermore you are using ancient old plugins ... please check https://maven.apache.org/plugins/ follow the conventions ... – khmarbaise Aug 19 '22 at 06:52

1 Answers1

0

To have the include with specific folder name and also in the maven resources plugin, specify the destination folder, something like this:

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
    <execution>
        <id>copy-resource-one</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>copy-resources</goal>
        </goals>
        <configuration>
            <outputDirectory>${basedir}/target/destination-folder</outputDirectory>
            <resources>
                <resource>
                    <directory>source-files</directory>
                    <includes>
                        <include>foo.txt</include>
                    </includes>
                </resource>
            </resources>
        </configuration>
    </execution>
</executions>
kma
  • 72
  • 1
  • 9