2011-09-08 107 views
1

如何將多個webapps WAR文件部署到Jetty 8中maven-jetty-plugin將多個war文件部署到jetty8

<contextHandlers> 
    <contextHandler implementation="org.mortbay.jetty.webapp.WebAppContext"> 
    <war>${basedir}/dir/mywar.war</war> 
    <contextPath>/path</contextPath> 
</contextHandler> 

似乎只適用於舊插件版本。

回答

1

從pom.xml中使用以下片段。這是根據Jetty服務器說明改編的,儘管它適用於Jetty7,但它可以輕鬆適用於更高版本。

的pom.xml

<plugin> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>maven-jetty-plugin</artifactId> 
    <!-- Jetty 7.3+ requires Maven 3+ --> 
    <!-- Keep with Jetty 7.6.0 to avoid startup delays from Servlet API 3.0 --> 
    <version>7.6.0.RC1</version> 
    <configuration> 
     <stopKey>STOP</stopKey> 
     <stopPort>8009</stopPort> 
     <scanIntervalSeconds>10</scanIntervalSeconds> 
     <!-- Provide some JNDI resources (optional) --> 
     <jettyEnvXml>src/test/resources/jetty-jndi-config.xml</jettyEnvXml> 
     <!-- Register this application as a context --> 
     <webAppConfig> 
     <contextPath>/example</contextPath> 
     </webAppConfig> 
     <!-- Allow resources on the test classpath to be available --> 
     <useTestClasspath>true</useTestClasspath> 
     <!-- Add in any supporting application contexts (use dependencies section) --> 
     <contextHandlers> 
     <!-- Supporting WAR (note the use of a property entry for version, and see the dependency later - also Jetty 7 uses org.eclipse...) --> 
     <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext"> 
      <war> 
      ${settings.localRepository}/org/example/supporting-war/${supporting-war.version}/supporting-war-${supporting-war.version}.war 
      </war> 
      <contextPath>/supporting-war</contextPath> 
     </contextHandler> 
     </contextHandlers> 
     <connectors> 
     <!-- Later versions of Jetty don't require the Connector to be specified --> 
     <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 
      <port>8080</port> 
      <maxIdleTime>60000</maxIdleTime> 
     </connector> 
     <!-- SSL for localhost support --> 
     <connector implementation="org.mortbay.jetty.security.SslSocketConnector"> 
      <port>8443</port> 
      <maxIdleTime>60000</maxIdleTime> 
      <!-- Provide a local key store for serving up SSL certificates --> 
      <keystore>src/test/resources/jetty-ssl.keystore</keystore> 
      <!-- Pick any password you like --> 
      <password>jetty6</password> 
      <keyPassword>jetty6</keyPassword> 
     </connector> 
     </connectors> 
    </configuration> 
    <dependencies> 
     <!-- This ensures that WAR files are downloaded from the repo --> 
     <!-- Example supporting WAR --> 
     <dependency> 
     <groupId>org.example</groupId> 
     <artifactId>supporting-war</artifactId> 
     <version>${supporting-war.version}</version> 
     <scope>compile</scope> 
     <type>war</type> 
     </dependency> 
    </dependencies> 
    </plugin> 

我已經離開了SSL和JNDI配置在那裏以防萬一有人需要,看看他們是如何配置的。顯然,他們將需要支持文件。 SSL假定您已經創建了一個合適的密鑰存儲區,其中包含localhost的SSL證書。 JNDI的配置文件如下:

碼頭-JNDI-config.xml中

<?xml version="1.0"?> 
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> 

<Configure class="org.mortbay.jetty.webapp.WebAppContext"> 
    <New id="ExampleDB" class="org.mortbay.jetty.plus.naming.Resource"> 
    <Arg>java:jdbc/ExampleDB</Arg> 
    <Arg> 
     <New class="com.mchange.v2.c3p0.ComboPooledDataSource"> 
     <Set name="driverClass">oracle.jdbc.driver.OracleDriver</Set> 
     <Set name="jdbcUrl">jdbc:oracle:thin:@//host:port/schema</Set> 
     <Set name="user">user</Set> 
     <Set name="password">password</Set> 
     <!-- Configure a simple connection test with timeout for subsequent queries --> 
     <Set name="preferredTestQuery">select 1 from dual</Set> 
     <Set name="checkoutTimeout">5000</Set> 
     </New> 
    </Arg> 
    </New> 
</Configure> 

這將允許使用JNDI查找資源,例如,一個Spring bean工廠是這樣的:

<bean id="exampleDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
    <property name="jndiName" value="java:jdbc/ExampleDB"/> 
    <property name="resourceRef" value="true"/> 
    </bean> 

請注意,C3P0和Oracle引用將引入對您的Jetty服務器來說表面上是本地的依賴性,所以應該將其與WAR一起放入<plugin><dependencies>部分。它們不必位於主要依賴項中。

因此,現在您的Maven構建將包含嵌入式Jetty Web服務器,該Web服務器配置爲與多個WAR一起工作,所有這些都與pom.xml版本綁定在一起,提供HTTP和HTTPS並支持池式數據庫連接。這幾乎是您爲集成開發環境開箱即用所需的一切。