简体   繁体   中英

maven does not copy property file to specified destination in tomcat

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

在此处输入图像描述

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.

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM