简体   繁体   中英

How to Run jetty on different maven profile

I am using maven-jetty-plugin .I have created two profile for test and development. Here is my 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>

So,when i run jetty:run i want to profile it for test and development.

Like jetty:run -Ptest for test profile and jetty:run -Pdevelopment .

When i run jetty:run -Ptest it does not work. Do i need to do extra configuration to make it run? If it is not possible from plugin then is there any alternative to run jetty on different maven profile? Any help please ?

You have neither bound the jetty plug in to a phase nor did you give it a goal to execute. Contrary to many other plugins, the jetty-maven-plugin's goals are not tied to default phases. BTW: You are using a hopelessly outdated version of the jetty-plugin. Since that time, it moved away from mortbay to eclipse foundation and got a major revamp - at least one time. I have adjusted the example below accordingly:

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

I defined in my IntelliJ a new maven command, as following:

clean package jetty:run -Pdev

It should work! The profile dev was used to replace params in config files during development phase.

I still use jetty plugin from mortbay:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM