Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 configure the connectors in the pom.xml?

Cheers

Nik

like image 431
niklassaers Avatar asked Sep 08 '10 13:09

niklassaers


3 Answers

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>
like image 120
Chris Eineke Avatar answered Oct 16 '22 12:10

Chris Eineke


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

like image 30
The Alchemist Avatar answered Oct 16 '22 12:10

The Alchemist


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.

like image 22
amacleod Avatar answered Oct 16 '22 11:10

amacleod