2010-09-08 96 views

回答

6

不幸的是,做一些研究之后,我不认为有编辑server.xml的连接方式。 mvn tomcat:run使用嵌入式Tomcat。

除非有人发现某些东西,否则您最好的办法是转移到maven cargo plugin并使用您的自定义server.xml将自己的Tomcat安装到ZIP上。

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

或诸如此类的东西...

+0

看来你是对的,也没有办法做到这一点比我自己的滚动破解,比如通过货运插件等的那一刻。 – niklassaers 2010-09-16 07:49:40

1

看到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作为模板来获取pr operty更换:

<Server port="@[email protected]" shutdown="SHUTDOWN" debug="@[email protected]"> 

    <Service name="Catalina" debug="@[email protected]"> 

    <Connector port="@[email protected]" 
     maxThreads="150" minSpareThreads="25" maxSpareThreads="75" 
     enableLookups="false" redirectPort="8443" acceptCount="100" 
     connectionTimeout="20000" disableUploadTimeout="true" 
     scheme="@[email protected]" secure="@[email protected]" 
     debug="@[email protected]" 
     emptySessionPath="@[email protected]" 
     URIEncoding="@[email protected]" /> 

    <!-- Define an AJP 1.3 Connector on port @[email protected] --> 
    <Connector port="@[email protected]" protocol="AJP/1.3" redirectPort="8443" /> 

    <Engine name="Catalina" defaultHost="@[email protected]" 
     debug="@[email protected]"> 

     <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="@[email protected]" 
      However, doing this result in a NullPointerException in 
      ExpandWar.java at line 145. --> 
     <Host name="@[email protected]" appBase="webapps" unpackWARs="true" 
      autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> 

     <!-- Contexts to explicitely point to where the wars are located --> 
     @[email protected] 

     <Valve className="org.apache.catalina.valves.AccessLogValve" 
      directory="logs" prefix="@[email protected]_access_log." suffix=".txt" 
      pattern="common" resolveHosts="false"/> 

     </Host> 
    </Engine> 
    </Service> 
</Server> 
3

我一直在使用serverXml参数为tomcat:run目标(http://tomcat.apache.org/maven-plugin-2/tomcat6-maven-plugin/run-mojo试验。 HTML#serverXml)。

以下server.xml似乎运行没有错误,但没有Context元素它不加载webapp。我想,如果我从SRC复制我Context元/主/ web应用/ 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

7

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