MVN TOMCAT:运行 - 如何编辑Server.xml?
-
01-10-2019 - |
题
我想从命令行中运行“ MVN tomcat:run”,但是如何在连接器中编辑server.xml以在连接器中设置maxhttpheadersize =“ 65536”?还是可以在pom.xml中配置连接器?
干杯
尼克
解决方案
不幸的是,在进行了一些研究之后,我认为没有一种编辑Server.xml连接器的方法。 mvn tomcat:run
使用嵌入式tomcat。
除非有人找到东西,否则最好的选择是搬到 Maven货物插件 并使用您的自定义来将您自己的tomcat安装安装 server.xml
.
<cargo containerId="tomcat7x" [...]>
<zipUrlInstaller
installUrl="file://tomcat-custom.zip",
installDir="target/installs"/>
[...]
</cargo>
或类似的东西...
其他提示
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>
我一直在尝试使用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的插件版本。
看 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>
并使用默认的货物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>