【问题标题】:mvn tomcat:run - how do I edit server.xml?mvn tomcat:run - 如何编辑 server.xml?
【发布时间】:2010-09-08 13:02:04
【问题描述】:

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

干杯

尼克

【问题讨论】:

    标签: java tomcat server.xml


    【解决方案1】:

    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>
    

    【讨论】:

      【解决方案2】:

      不幸的是,在做了一些研究之后,我认为没有办法编辑 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>
      

      或者类似的东西......

      【讨论】:

      • 看来你是对的,目前除了通过 cargo 插件滚动我自己的 hack 之外,没有其他办法。
      【解决方案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
      

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

      【讨论】:

        【解决方案4】:

        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-06-11
          • 1970-01-01
          • 2022-01-17
          • 2010-11-13
          • 2011-12-11
          • 2013-07-10
          • 1970-01-01
          • 1970-01-01
          • 2012-10-24
          相关资源
          最近更新 更多