【问题标题】:How do I copy a file to tomcat webapp folder using maven?如何使用 maven 将文件复制到 tomcat webapp 文件夹?
【发布时间】:2011-02-03 11:56:01
【问题描述】:

我想使用 Maven 将资源文件从 src/main/resources 复制到 /target/tomcat6x/container/webapps 中的 Cargo Tomcat

我尝试使用maven-resources-plugin,但没有任何成功。

我试过了:

<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>

...但是在服务器启动并且应用程序被 ping 通之前文件没有被复制。

有人知道如何正确使用吗?

【问题讨论】:

    标签: java maven tomcat6


    【解决方案1】:

    您可以为此使用 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>
    

    【讨论】:

    • 感谢@K。 Claszen 因为它会与 maven cargo 一起使用,如果 maven cargo 目录中有任何内容,它会删除它。所以最好使用 maven cargo 插件并提及阶段。但我不知道该怎么做。
    • 嗨,非常感谢,最后,我最终使用了您的解决方案,而是将其复制到临时货物 tomcat webapps。所以没有冲突。再次感谢。
    【解决方案2】:

    好的,这就是答案。:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多