开发者

mvn tomcat:run - how do I edit server.xml?

I want to run "mvn tomcat:run" from the command line, but how can I edit the server.xml to set maxHttpHeaderSize="65536" in the connectors? Or can I con开发者_运维问答figure the connectors in the pom.xml?

Cheers

Nik


The org.codehaus.mojo:tomcat-maven-plugin will let you set the path to the server.xml file in the configuration section:

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


Unfortunately, after doing some research, I don't think there's a way to edit server.xml's connectors. mvn tomcat:run uses an embedded Tomcat.

Unless someone finds something, it seems like your best bet will be to move to the maven cargo plugin and ZIP up your own Tomcat installation with your custom server.xml.

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

Or something of the sort...


I have been experimenting with using the serverXml parameter for the tomcat:run goal (http://tomcat.apache.org/maven-plugin-2/tomcat6-maven-plugin/run-mojo.html#serverXml).

The following server.xml seems to run with no errors, but without a Context element it does not load the webapp. I think if I copied my Context element from src/main/webapp/META-INF/context.xml to inside the Host element, it might work just fine:

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

To run with this server, I pass the serverXml as a property on the Maven command line:

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

The goal might have to be tomcat6:run if you are using a version of the plugin that supports both Tomcat 6 and 7.


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

i think you can do it like this and place your custom server.xml in your project:

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

and use default cargo server.xml as a template to get property replacement:

<Server port="@cargo.rmi.port@" shutdown="SHUTDOWN" debug="@catalina.logging.level@">

  <Service name="Catalina" debug="@catalina.logging.level@">

    <Connector port="@cargo.servlet.port@"
        maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
        enableLookups="false" redirectPort="8443" acceptCount="100"
        connectionTimeout="20000" disableUploadTimeout="true"
        scheme="@cargo.protocol@" secure="@catalina.secure@"
        debug="@catalina.logging.level@"
        emptySessionPath="@catalina.connector.emptySessionPath@"
        URIEncoding="@catalina.servlet.uriencoding@" />

    <!-- Define an AJP 1.3 Connector on port @cargo.tomcat.ajp.port@ -->
    <Connector port="@cargo.tomcat.ajp.port@" protocol="AJP/1.3" redirectPort="8443" />

    <Engine name="Catalina" defaultHost="@cargo.hostname@" 
        debug="@catalina.logging.level@">

      <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="@catalina.logging.level@"
           However, doing this result in a NullPointerException in 
           ExpandWar.java at line 145. -->
      <Host name="@cargo.hostname@" appBase="webapps" unpackWARs="true"
          autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

        <!-- Contexts to explicitely point to where the wars are located -->
        @tomcat.webapps@

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

      </Host>
    </Engine>
  </Service>
</Server>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜