2011-09-08 171 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并支持池式数据库连接。这几乎是您为集成开发环境开箱即用所需的一切。