Wednesday, 19 December 2012

Servlet 3 with Jetty and Maven

To deploy a servlet 3 web app in jetty you need to use jetty 8. To run jetty 8 from maven use the jetty-maven-plugin NOT the maven-jetty-plugin. The maven-jetty-plugin will not work with servlet 3 apps.

Add the following to your pom:

<build>
  <plugins>
    <plugin>
      <groupid>org.mortbay.jetty</groupId>
      <artifactid>jetty-maven-plugin</artifactId>
      <version>8.1.5.v20120716</version>
      <configuration>
         <!-- Periodically scan to reload servlet if changes found -->
         <scanintervalseconds>10</scanintervalseconds>
          
         <!-- Path where servlet will be accessed in this case http://localhost:9090/MyApp-->
          <webapp>
            <contextpath>/MyApp</contextpath>
          </webapp>
          <connectors>
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
              <port>9090</port>
            </connector>
          </connectors>
      </configuration>
    </plugin>
  </plugins>
</build>

If you are using the usual locations for config files then the plugin should pick up the configurations. To configure the plugin with additional settings go to: http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin#Configuring_Your_WebApp

Now to run your web app with jetty, use the following gaol:



3 comments:

  1. I think this is the best article today. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Keep sharing your information regularly for my future reference.
    Java Courses in chennai

    ReplyDelete
  2. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    Digital Marketing Training

    ReplyDelete
  3. I think this is an informative post and knowledgeable. Thank you for sharing this wonderful post! I’m glad that I came across your article.
    Java Training in Chennai/Java Training in Chennai with Placements

    ReplyDelete