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

发布于 2024-09-18 09:48:09 字数 130 浏览 2 评论 0原文

我想从命令行运行“mvn tomcat:run”,但如何编辑 server.xml 以在连接器中设置 maxHttpHeaderSize="65536" ?或者我可以在 pom.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 configure the connectors in the pom.xml?

Cheers

Nik

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

初见终念 2024-09-25 09:48:09

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>

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>
妥活 2024-09-25 09:48:09

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

除非有人找到了一些东西,否则你最好的选择似乎是转移到 maven Cargo 插件 并压缩使用自定义 server.xml 安装您自己的 Tomcat。

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

或者类似的东西...

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

╄→承喏 2024-09-25 09:48:09

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

以下 server.xml 似乎运行时没有错误,但如果没有 Context 元素,它不会加载 Web 应用程序。我想如果我将 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

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.

柠栀 2024-09-25 09:48:09

请参阅http://docs.codehaus.org/display/CARGO/Custom+File+配置

认为你可以这样做,并将自定义的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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文