我希望能够在命令行中运行"mvn tomcat:run"命令,但是我该如何编辑server.xml文件以设置连接器中的maxHttpHeaderSize="65536"呢?或者我可以在pom.xml文件中配置这些连接器吗?
谢谢,
Nik
谢谢,
Nik
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>
mvn tomcat:run
使用嵌入式Tomcat。server.xml
与Tomcat安装一起打包成ZIP文件。<cargo containerId="tomcat7x" [...]>
<zipUrlInstaller
installUrl="file://tomcat-custom.zip",
installDir="target/installs"/>
[...]
</cargo>
tomcat:run
目标的serverXml参数(http://tomcat.apache.org/maven-plugin-2/tomcat6-maven-plugin/run-mojo.html#serverXml)进行实验。server.xml
似乎没有错误,但是没有Context
元素时,它不会加载Web应用程序。我认为,如果我将src/main/webapp/META-INF/context.xml中的Context
元素复制到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
。
请查看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>