2010-09-08 83 views

回答

6

不幸的是,做一些研究之後,我不認爲有編輯server.xml的連接方式。 mvn tomcat:run使用嵌入式Tomcat。

除非有人發現某些東西,否則您最好的辦法是轉移到maven cargo plugin並使用您的自定義server.xml將自己的Tomcat安裝到ZIP上。

<cargo containerId="tomcat7x" [...]> 
    <zipUrlInstaller 
     installUrl="file://tomcat-custom.zip", 
     installDir="target/installs"/> 
    [...] 
</cargo> 

或諸如此類的東西...

+0

看來你是對的,也沒有辦法做到這一點比我自己的滾動破解,比如通過貨運插件等的那一刻。 – niklassaers 2010-09-16 07:49:40

1

看到http://docs.codehaus.org/display/CARGO/Custom+File+Configurations

認爲你能做到這樣,並把您的自定義的server.xml在您的項目:

<configuration> 
    <type>standalone</type> 
    <configfiles> 
     <configfile> 
      <file>${basedir}/src/main/resources/server.xml</file> 
      <todir>conf</todir> 
     </configfile> 
    </configfiles> 
</configuration> 

並使用默認貨物server.xml作爲模板來獲取pr operty更換:

<Server port="@[email protected]" shutdown="SHUTDOWN" debug="@[email protected]"> 

    <Service name="Catalina" debug="@[email protected]"> 

    <Connector port="@[email protected]" 
     maxThreads="150" minSpareThreads="25" maxSpareThreads="75" 
     enableLookups="false" redirectPort="8443" acceptCount="100" 
     connectionTimeout="20000" disableUploadTimeout="true" 
     scheme="@[email protected]" secure="@[email protected]" 
     debug="@[email protected]" 
     emptySessionPath="@[email protected]" 
     URIEncoding="@[email protected]" /> 

    <!-- Define an AJP 1.3 Connector on port @[email protected] --> 
    <Connector port="@[email protected]" protocol="AJP/1.3" redirectPort="8443" /> 

    <Engine name="Catalina" defaultHost="@[email protected]" 
     debug="@[email protected]"> 

     <Realm className="org.apache.catalina.realm.MemoryRealm" /> 

     <!-- Note: There seems to be a bug in Tomcat 5.x if the debug attribute 
      is present. Ideally we would have written: 
       debug="@[email protected]" 
      However, doing this result in a NullPointerException in 
      ExpandWar.java at line 145. --> 
     <Host name="@[email protected]" appBase="webapps" unpackWARs="true" 
      autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> 

     <!-- Contexts to explicitely point to where the wars are located --> 
     @[email protected] 

     <Valve className="org.apache.catalina.valves.AccessLogValve" 
      directory="logs" prefix="@[email protected]_access_log." suffix=".txt" 
      pattern="common" resolveHosts="false"/> 

     </Host> 
    </Engine> 
    </Service> 
</Server> 
3

我一直在使用serverXml參數爲tomcat:run目標(http://tomcat.apache.org/maven-plugin-2/tomcat6-maven-plugin/run-mojo試驗。 HTML#serverXml)。

以下server.xml似乎運行沒有錯誤,但沒有Context元素它不加載webapp。我想,如果我從SRC複製我Context元/主/ web應用/ META-INF/context.xml中的Host元素中,它可能會工作得很好:

<?xml version='1.0' encoding='utf-8'?> 
<Server port="-1" shutdown="SHUTDOWN"> 
    <Service name="Catalina"> 
     <Connector port="8080" protocol="HTTP/1.1" /> 
     <Engine name="Catalina" defaultHost="localhost"> 
      <Host name="localhost" appBase="webapps"> 
      </Host> 
     </Engine> 
    </Service> 
</Server> 

要使用此服務器上運行,我通過serverXml作爲Maven的命令行上的屬性:

mvn -Dmaven.tomcat.serverXml=src/main/resources/server.xml tomcat:run 

的目標可能要tomcat6:run如果您正在使用一個版本,同時支持Tomcat的6和7

7

的org.codehaus的插件。 mojo:tomcat-maven-plugin會讓你等路徑在配置部分server.xml文件:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>tomcat-maven-plugin</artifactId> 
    <configuration> 
    <serverXml>path_to_server_xml_file</serverXml> 
    </configuration> 
</plugin>