java - 如何在不同的 Maven 配置文件上运行 jetty

标签 java maven maven-jetty-plugin

我正在使用ma​​ven-jetty-plugin。我创建了两个用于测试和开发的配置文件。 这是我的 pom

<profiles>
      <profile>
      <id>test</id>
      <build>

    <finalName>Authorization</finalName>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.1</version>
            <executions>
               <execution>
                  <phase>test</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
         <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.10</version>
        <configuration>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8080</port>
              <maxIdleTime>60000</maxIdleTime>
            </connector>
          </connectors>
        </configuration>
      </plugin>
      </plugins>
      </build>
      </profile>
        <profile>
      <id>development</id>
      <build>

    <finalName>AuthorizationTest</finalName>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.1</version>
            <executions>
               <execution>
                  <phase>test</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
      </build>
      </profile>
   </profiles>

所以,当我运行 jetty:run 时,我想对其进行分析以进行测试和开发。

喜欢 jetty:run -Ptest 用于测试配置文件和 jetty:run -Pdevelopment

当我运行 jetty:run -Ptest 时,它不起作用。我需要做额外的配置才能使其运行吗? 如果插件无法实现,那么还有其他选择吗在不同的maven配置文件上运行jetty?请问有什么帮助吗?

最佳答案

您既没有将 jetty 插件绑定(bind)到某个阶段,也没有给它一个执行目标。与许多其他插件相反,jetty-maven-plugin 的目标与默认阶段无关。顺便说一句:您正在使用 jetty 插件的过时版本。从那时起,它从 mortbay 搬到了 eclipse 基金会,并进行了一次重大改造——至少一次。我相应地调整了下面的示例:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mwmahlberg.examples</groupId>
<artifactId>start-jetty-in-profiles</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Adjust to your packaging here -->
<packaging>pom</packaging>

<profiles>
  <profile>
    <id>test</id>
    <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <executions>
          <execution>
            <!-- this will fire up jetty as soon as you reach the integration-test phase in the test profile -->
            <phase>integration-test</phase>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <connectors>
            <connector implementation="org.eclipse.jetty.nio.SelectChannelConnector">
              <port>8080</port>
              <maxIdleTime>60000</maxIdleTime>
            </connector>
          </connectors>
        </configuration>
      </plugin>
    </plugins>
    </build>
  </profile>

  <profile>
    <id>development</id>
  </profile>
</profiles>
</project>

关于java - 如何在不同的 Maven 配置文件上运行 jetty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23125786/

相关文章:

java - Maven 返回编译失败 : package com. mashape.unirest.http 不存在

Java - Maven - 在表单中设置图标图像

java - ClassNotFoundException:对 PMD 规则集使用自定义 java 规则

java - 如何使用 Action 监听器检查是否单击了某个按钮?

java - tomcat web应用程序的并行编程

java - HTTP错误: 503 Reason: Service Unavailable powered by jetty

java - jelly.config 中的可选 block 不会转换到 jenkins 插件开发中的后端。

jetty - 如何在 xsbt-web-plugin 上设置 jetty 的 contextPath?

java - Java 中的 C++ 类型定义?

java - Android Eclipse项目中调用java方法 "for the second time"时如何处理