【问题标题】:How to Run jetty on different maven profile如何在不同的 Maven 配置文件上运行码头
【发布时间】:2014-06-01 06:58:36
【问题描述】:

我正在使用 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 配置文件上运行码头?请帮忙?

【问题讨论】:

    标签: java maven maven-jetty-plugin


    【解决方案1】:

    我在 IntelliJ 中定义了一个新的 maven 命令,如下所示:

    clean package jetty:run -Pdev
    

    它应该工作!配置文件 dev 用于在开发阶段替换配置文件中的参数。

    我仍然使用 mortbay 的 jetty 插件:

    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.4.5.v20110725</version>
    

    【讨论】:

      【解决方案2】:

      您既没有将码头插件绑定到一个阶段,也没有给它一个执行目标。与许多其他插件相反,jetty-maven-plugin 的目标与默认阶段无关。顺便说一句:您正在使用一个无可救药的过时版本的 jetty-plugin。从那时起,它从 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-26
        • 2015-06-16
        • 2017-01-20
        • 2015-05-22
        • 1970-01-01
        • 1970-01-01
        • 2016-12-12
        • 2011-09-23
        相关资源
        最近更新 更多