8

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

干杯

尼克

4

4 回答 4

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>
于 2012-09-12T15:20:20.890 回答
6

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

除非有人发现了什么,否则您最好的选择似乎是转移到maven cargo 插件并使用您自定义的 .zip 压缩您自己的 Tomcat 安装server.xml

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

或者类似的东西...

于 2010-09-08T13:27:16.563 回答
3

我一直在尝试使用 serverXml 参数来实现tomcat:run目标(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

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

于 2012-08-20T00:01:21.350 回答
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>

并使用默认的 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>
于 2011-02-01T21:06:09.243 回答