Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webdevelopment with Jetty & Maven

I find it very frustrating doing web development with Maven & Jetty using Eclipse, compare with what I did using Visual Studio. Everytime I make a change, even a minor change in my view file, (*.jsp, for example), then I have to re-package the whole web -> waiting for jetty to reload everything before I can see the change.

Is there any better way to do that, some thing like an automatically plugin that will picked that changed files and deploy the changed files to web server?

like image 722
Phương Nguyễn Avatar asked Mar 23 '10 03:03

Phương Nguyễn


1 Answers

The way you are using Maven, Jetty (and Eclipse) together is unclear but since the question is tagged Maven, I'll cover the Maven way. With a project of type war, one easy way to get the webapp up and running is to use the Maven Jetty Plugin. To do so, simply add the following snippet to your POM:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.10</version>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

With this setup, running mvn jetty:run will start a jetty container with your application deployed. Any change on a view will cause the JSP to be recompiled when requested. And to configure the jetty plugin to also watch for Java code changes, you'll have to add the scanIntervalSeconds option:

scanIntervalSeconds Optional. The pause in seconds between sweeps of the webapp to check for changes and automatically hot redeploy if any are detected. By default this is 0, which disables hot deployment scanning. A number greater than 0 enables it.

So the configuration might look like:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.10</version>
        <configuration>
          <scanIntervalSeconds>1</scanIntervalSeconds>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

And if you want to be able to connect a remote debugger, have a look at these instructions.

This is how I've always used Jetty with Maven and Eclipse, and I've always been happy with this setup. I've never used the Jetty adapter for the WTP, the previous setup is just unbeatable.

like image 99
Pascal Thivent Avatar answered Sep 23 '22 06:09

Pascal Thivent