开发者

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 开发者_如何学JAVAwhole 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?


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.


Haven't used Jetty with Eclipse, but if you use Tomcat (and I assume Jetty would work as well) with WTP and the m2eclipse plugin, Eclipse will build and publish your web application every time a resource is saved.

  1. Create (or use existing) Maven project with 'war' packaging.

  2. In the Eclipse "servers" view, right-click and set up a server.

  3. Right click on the configured server, and choose "Add/Remove projects", and select your project.

  4. Click on the green triangle in the servers view to start up the server.

Now Eclipse should auto-build-and-publish your Web application every time you make a change. Note, you must have the m2eclipse plugin AND the m2eclipse WTP integration plugin for this to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜