maven中tomcat和jetty嵌入式插件設置虛擬目錄.web
maven-jetty-plugin版本9.2.10.v20150310apache
<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中配置的資料未找到.tomcat
因此只能採起另外的作法,使用server.xmlapp
增長server.xml文件.eclipse
<?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 中增長這個配置文件設置webapp
<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>