简体   繁体   English

如何使用maven将文件复制到tomcat webapp文件夹?

[英]How do I copy a file to tomcat webapp folder using maven?

I want to copy a resource file from src/main/resources to Cargo Tomcat in /target/tomcat6x/container/webapps using Maven . 我想使用Maven将资源文件从src / main / resources复制到/ target / tomcat6x / container / webapps中的Cargo Tomcat

I tried using maven-resources-plugin but am not having any success. 我尝试使用maven-resources-plugin但没有取得任何成功。

I tried this: 我试过这个:

<plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.0.5</version>
            <configuration>
                <wait>false</wait>
                <container>
                    <containerId>tomcat6x</containerId>
                    <zipUrlInstaller>
                        <url>
                            http://mirrors.enquira.co.uk/apache/tomcat/tomcat-6/v6.0.30/bin/apache-tomcat-6.0.30.zip
                        </url>
                        <installDir>${installDir}</installDir>
                    </zipUrlInstaller>
                    <output>
                        ${project.build.directory}/tomcat6x.log
                    </output>
                    <log>${project.build.directory}/cargo.log</log>
                </container>
                <configuration>
                    <files>
                        <copy>
                          <file>src/main/resources/datasource.properties</file>
                          <!--tofile>${project.build.directory}/tomcat6x/container/webapps/datasource.properties</tofile-->
                          <todir>${project.build.directory}/tomcat6x/container/webapps</todir>
                        </copy>
                    </files>
                    <home>
                        ${project.build.directory}/tomcat6x/container
                    </home>
                    <properties>
                        <cargo.logging>high</cargo.logging>
                        <cargo.servlet.port>8081</cargo.servlet.port>
                    </properties>
                </configuration>
            </configuration>


            <executions>
                <execution>
                    <id>start-container</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>configure</goal>
                        <goal>start</goal>
                        <goal>deploy</goal>
                    </goals>
                    <configuration>
                        <deployer>
                            <deployables>
                                <deployable>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <type>war</type>
                                    <pingURL>http://localhost:8081/charmweb-0.0.1-SNAPSHOT/</pingURL>
                                    <pingTimeout>180000</pingTimeout> 
                                    <properties>
                                        <context>charmweb-0.0.1-SNAPSHOT</context>
                                    </properties>
                                </deployable>
                            </deployables>
                        </deployer>
                    </configuration>
                </execution>

                <execution>
                    <id>stop-container</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

... but the file is not copying before the server starts and the application gets pinged. ...但是在服务器启动和应用程序被ping之前文件没有复制。

Does anyone know how to use it properly? 有谁知道如何正确使用它?

You can use the maven-antrun-plugin for this and execute an ant copy task: 您可以使用maven-antrun-plugin执行此操作并执行ant复制任务:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <target>
                    <copy file="src/main/resources/fileToCopy"
                        tofile="${project.build.directory}/tomcat6x/container/webapps/fileToCopy" />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

ok here is the answer.: 好的,这里的答案是:

<plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.0.5</version>
            <configuration>
                <wait>false</wait>
                <container>
                    <containerId>tomcat6x</containerId>
                    <zipUrlInstaller>
                        <url>
                            http://mirrors.enquira.co.uk/apache/tomcat/tomcat-6/v6.0.30/bin/apache-tomcat-6.0.30.zip
                        </url>
                        <installDir>${installDir}</installDir>
                    </zipUrlInstaller>
                    <output>
                        ${project.build.directory}/tomcat6x.log
                    </output>
                    <log>${project.build.directory}/cargo.log</log>
                </container>
                <configuration>
                    <home>
                        ${project.build.directory}/tomcat6x/container
                    </home>
                    <properties>
                        <cargo.logging>high</cargo.logging>
                        <cargo.servlet.port>8081</cargo.servlet.port>
                    </properties>
                    <files>
                        <copy>
                          <file>${project.basedir}/src/main/resources/datasource.properties</file>
                          <todir>webapps</todir>
                          <configfile>true</configfile>
                          <overwrite>true</overwrite>
                        </copy>
                    </files>
                </configuration>
            </configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Maven和Eclipse将资源复制到webapp目录? - How do I copy resources to webapp directory using Maven and Eclipse? 如何使用 Maven 复制文件并将第一个模块指定为目标文件夹? - How do I copy a file using Maven and specify the first module as the target folder? 如何读取在 apache tomcat 中运行的 web 应用程序的清单文件? - How do I read the manifest file for a webapp running in apache tomcat? 如何使用 Spring(Tomcat 服务器)和 Maven 创建 webapp? - How can I create a webapp with Spring (Tomcat server) and Maven? 如何使用tomcat / maven运行.war文件? - How do I run a .war file with tomcat/maven? 从tomcat webapp文件夹生成war文件 - Generate war file from tomcat webapp folder 使用生成的webapp文件夹将Maven项目部署到Apache Tomcat - Deploy a Maven project with a generated webapp folder to Apache Tomcat 如何在Maven中从src / main / resources复制文件? - How do I copy a file from src/main/resources in Maven? 在 Java Maven 项目中,如何使用 selenium 从资源文件夹上传文件(照片) - In Java Maven project how do I upload file (photo) from resource folder using selenium 如何将文件夹添加到由Maven cargo插件启动的Tomcat容器的类路径中 - How do I add a folder to the classpath of a Tomcat container being started by the maven cargo plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM