maven中tomcat和jetty嵌入式插件設置虛擬目錄.

maven-jetty-plugin版本9.2.10.v20150310

Xml代碼
<plugin>  
    <groupId>org.eclipse.jetty</groupId>  
    <artifactId>jetty-maven-plugin</artifactId>  
    <version>${jetty.version}</version>  
    <configuration>  
        <encoding>UTF-8</encoding>  
        <scanIntervalSeconds>10</scanIntervalSeconds>  
        <contextXml>${project.basedir}/src/test/resources/jetty-context.xml</contextXml>  
        <!-- <jettyXml>${project.basedir}/src/test/resources/jetty.xml</jettyXml> -->  
         <webAppConfig>    
             <defaultsDescriptor>${project.basedir}/src/test/resources/webdefault.xml</defaultsDescriptor>    
        </webAppConfig>      
        <stopKey>foo</stopKey>  
        <stopPort>9999</stopPort>  
        <webApp>  
            <contextPath>/</contextPath>  
        </webApp>  
        <!-- 額外監聽目錄 -->  
        <contextHandlers>  
            <!-- 附件目錄服務 -->  
            <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">  
                <contextPath>/upload</contextPath>  
                <resourceBase>/home/baseos/upload/</resourceBase>  
            </contextHandler>  
        </contextHandlers>  
    </configuration>  
    <executions>  
        <execution>  
            <id>start-jetty</id>  
            <phase>pre-integration-test</phase>  
            <goals>  
                <goal>run</goal>  
            </goals>  
            <configuration>  
                <scanIntervalSeconds>0</scanIntervalSeconds>  
                <daemon>true</daemon>  
            </configuration>  
        </execution>  
        <execution>  
            <id>stop-jetty</id>  
            <phase>post-integration-test</phase>  
            <goals>  
                <goal>stop</goal>  
            </goals>  
        </execution>  
    </executions>  
</plugin>  

tomcat7-maven-plugin版本2.2 直接在pom中配置的資料未找到.

所以只能採取另外的做法,使用server.xml

增加server.xml文件.

Xml代碼

<?xml version="1.0" encoding="UTF-8"?>  
<Server port="8005" shutdown="SHUTDOWN">  
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>  
  <Listener className="org.apache.catalina.core.JasperListener"/>  
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>  
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>  
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>  
  <GlobalNamingResources>  
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>  
  </GlobalNamingResources>  
  <Service name="Catalina">  
    <Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443"/>  
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>  
  
    <Engine defaultHost="localhost" name="Catalina">  
      <Realm className="org.apache.catalina.realm.LockOutRealm">  
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>  
      </Realm>  
  
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">  
             <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>  
        <!-- 增加虛擬目錄配置-->  
             <Context docBase="d:/home/baseos/upload/" path="/upload" reloadable="true"/>  
      </Host>  
    </Engine>  
  </Service>  
</Server>  

tomcat7-maven-plugin 中增加這個配置文件設置

 

Xml代碼

<plugin>  
    <groupId>org.apache.tomcat.maven</groupId>  
    <artifactId>tomcat7-maven-plugin</artifactId>  
    <version>2.2</version>  
    <configuration>  
        <path>/</path>  
        <port>80</port>  
        <uriEncoding>UTF-8</uriEncoding>  
        <server>tomcat7</server>  
        <serverXml>${project.basedir}/src/test/resources/server.xml</serverXml>  
    </configuration>  
</plugin>  

轉載來處:http://wu1g119.iteye.com/blog/2220797

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章