2010-11-29 35 views

回答

13

尤里卡!經過多天研究這個問題,我終於找到了一個非常有效的解決方案。關鍵是要取出Tomcat XML上下文片段文件,並使用<configfiles>元素的貨物將其放入名稱爲context.xml.defaultconf/Catalina/localhost目錄中。唯一的缺點是這會讓你的上下文定義可用於所有的網絡應用程序,但這只是貨真價實的,因爲沒有其他的網絡應用程序。

這裏的配置:

<configuration> <!-- Deployer configuration --> 
    <type>standalone</type> 
    <properties> 
     <cargo.servlet.port>${tomcat6.port}</cargo.servlet.port> 
    </properties> 
    <deployables> 
     <deployable> 
     <groupId>com.myapp<groupId> 
     <artifactId>myapp-war</artifactId> 
     <type>war</type> 
     <properties> 
       <context>${tomcat6.context}</context> 
     </properties> 
     </deployable> 
    </deployables> 
    <configfiles> 
     <configfile> 
     <file>${basedir}/../config/tomcat-context.xml</file> 
     <todir>conf/Catalina/localhost/</todir> 
     <tofile>context.xml.default</tofile> 
     </configfile> 
    </configfiles> 
</configuration> 

最終的結果是沒有更多的假WAR模塊僅用於測試,和戰爭沒有更多的合併。希望這有助於某人。

+0

它工作除了貨物1.1.1接縫不添加新文件的事實。我只能替換文件。 – Ralph 2011-06-24 13:34:24

2

我還沒有找到辦法做到這一點,但我想出了一個解決方案,在我的項目中工作。我目前有基本3子模塊項目:

dependencies 
    webapp 
    smoketest 

當我正在創建的「Web應用」項目,我執行以下插件聲明:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>create-war-smoketest</id> 
     <phase>verify</phase> 
     <goals> 
      <goal>war</goal> 
     </goals> 
     <configuration> 
      <webappDirectory>${project.build.directory}/exploded</webappDirectory> 
      <primaryArtifact>false</primaryArtifact> 
      <classifier>smoketest</classifier> 
      <webResources> 
      <resource> 
       <filtering>true</filtering> 
       <directory>src/test/resources/smoketest</directory> 
       <targetPath>META-INF</targetPath> 
       <includes> 
        <include>context.xml</include> 
       </includes> 
      </resource> 
      </webResources> 
     </configuration> 
     </execution> 
    </executions> 
</plugin> 

然後當我跑步時我貨運/ WebTest的套件在SmokeTest項目中,我指定的smoketest WAR文件作爲依賴,並在我的貨物配置設置我deployrables正是如此:

<deployables> 
    <deployable> 
     <groupId>${pom.groupId}</groupId> 
     <artifactId>webapp</artifactId> 
     <type>war</type> 
     <properties> 
      <context>smoketest</context> 
     </properties> 
    </deployable> 
</deployables> 

有了依賴性升舉個例子:

<dependencies> 
    <dependency> 
     <groupId>${pom.groupId}</groupId> 
     <artifactId>webapp</artifactId> 
     <version>${pom.version}</version> 
     <classifier>smoketest</classifier> 
     <type>war</type> 
     <scope>system</scope> 
     <!-- trick the dependency plugin to never look for it in the repo --> 
     <systemPath>${basedir}/../webapp/target/webapp-${pom.version}-smoketest.war</systemPath> 
    </dependency> 
</dependencies> 

這是非常骯髒的,但它至少可以......現在。一個簡單的說明:關於強制它從不在回購中查找版本的評論在這一點上可能是不正確的;我認爲這個技巧可能在某些時候被依賴插件的改變破壞了。

+0

我也試過這個 - 它對我也適用。只是希望免除一次性WAR工件 - 因爲我們不希望/不能在其中發佈帶有過濾的context.xml文件的WAR。 – HDave 2010-11-30 03:08:09

相關問題