将多个war文件部署到jetty8中

发布于 2024-12-03 15:56:18 字数 340 浏览 1 评论 0原文

如何使用 maven-jetty-plugin 将多个 webapps WAR 文件部署到 Jetty 8 中?

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

似乎仅适用于较旧的插件版本。

How do I deploy multiple webapps WAR files into Jetty 8 with maven-jetty-plugin?

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

Seems to work only on older plugin versions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉目亦如画i 2024-12-10 15:56:18

使用 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 配置文件如下:

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

这将允许使用例如 Spring bean 工厂进行 JNDI 资源查找,如下所示:

<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 一起放置在 部分中。它们不必位于主要依赖项中。

因此,现在您的 Maven 构建将包含一个嵌入式 Jetty Web 服务器,配置为与多个 WAR 一起使用,所有这些都绑定到 pom.xml 版本中,提供 HTTP 和 HTTPS 并支持池数据库连接。这几乎就是集成开发环境开箱即用所需的一切。

Use the following snippet from a pom.xml. This is adapted from the Jetty server instructions, and although it's for Jetty7 it can easily be adapted for later versions.

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>

I've left the SSL and JNDI configuration in there just in case anyone needs to see how they are configured. Obviously, they will need the supporting files. The SSL assumes that you've already created a suitable key store containing an SSL certificate for, say, localhost. The JNDI configuration file is as follows:

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

This will allow a JNDI resource lookup using, for example, a Spring bean factory like this:

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

Note that the C3P0 and Oracle references will introduce dependencies that are ostensibly local to your Jetty server, so should be placed in the <plugin><dependencies> section along with the WARs. They don't have to be in the main dependencies.

So now your Maven build will contain an embedded Jetty web server, configured to work with multiple WARs, all tied into the pom.xml version, providing both HTTP and HTTPS and backed with a pooled database connection. That's pretty much everything you need right out of the box for an integrated development environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文