mvn tomcat:运行 - 如何编辑server.xml?

时间:2010-09-08 13:02:05

标签: java tomcat server.xml

我想从命令行运行“mvn tomcat:run”,但是如何编辑server.xml以在连接器中设置maxHttpHeaderSize =“65536”?或者我可以在pom.xml中配置连接器吗?

干杯

的Nik

4 个答案:

答案 0 :(得分:8)

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>

答案 1 :(得分:6)

不幸的是,在做了一些研究后,我认为没有办法编辑server.xml的连接器。 mvn tomcat:run使用嵌入式Tomcat。

除非有人发现某些内容,否则您最好的选择是转到maven cargo plugin并使用自定义server.xml压缩自己的Tomcat安装。

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

或类似的......

答案 2 :(得分:3)

我一直在尝试使用server tomcat:run目标的serverXml参数(http://tomcat.apache.org/maven-plugin-2/tomcat6-maven-plugin/run-mojo.html#serverXml )。

以下server.xml似乎运行时没有错误,但没有Context元素,它不会加载webapp。我想如果我将我的Context元素从src / main / webapp / 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

如果您使用的是支持Tomcat 6和7的插件版本,则目标可能必须为tomcat6:run

答案 3 :(得分: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>

并使用default cargo server.xml作为模板来获取属性:

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