2011-02-03 210 views
3

我想使用Maven在/ target/tomcat6x/container/webapps中將資源文件從src/main/resources複製到CargoTomcat如何使用maven將文件複製到tomcat webapp文件夾?

我試過使用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通。

有誰知道如何正確使用它?

回答

2

您可以使用maven-antrun-插件,這和執行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> 
+0

感謝@K。 Claszen因爲會用Maven貨物,如果Maven貨物的目錄裏有任何東西,它會刪除它。所以最好使用Maven貨物插件並提及階段。但我不知道如何。 – Ikthiander 2011-02-03 12:39:23

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> 
相關問題