RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Integrate the Eclipse Web Tools Platform and Maven : Page 4

Leveraging the Eclipse Web Tools Platform (WTP) and the M2Eclipse (M2) plugin in the same project has compelling benefits for the Java web developer.

Launching the Web Application from WTP
Now let's test the debugging functionality:
  1. Put a breakpoint in the servlet doGetMethod.
  2. Launch the application by right clicking on the project and executing "Debug As" (see Figure 10).
  3. Select "Debug on Server".
  4. If there is no option to use "Choose an existing server," use "Manually define a new server" only.

Figure 10. Launching the Web Application: Launch the application by right clicking on the project and executing "Debug As".

In the next page of the wizard screen, ensure that the project is showing up under "Configured projects". You can experiment with the debugging capabilities of WTP by placing breakpoints in JSPs or the servlet—or, for that matter, in any other code. If you encounter issues, you may need to relaunch after deleting the server shown in Figure 11. (You won't need it the first time.)

Eclipse will launch the browser and show the application in it. Depending on the breakpoint, Eclipse may go into the debug perspective. You can even set your breakpoints at runtime and see the effects. Alternatively, you can also launch using Run As→Run On Server in the same manner.

Verifying WTP and M2 Plugin Integration
Based on the output and debugging session, you can confirm whether or not the integration was successful.

Note: Changes you make to the servlet, simple classes, and JSPs get dynamically reflected in the output because WTP is pushing all changes into the server. If you don't need this feature, feel free to stop the server, or delete the server from the server view discussed above. Running Maven goals of "package" does not affect this functionality in anyway. In fact, all other Maven goals can be executed in the same manner.

Figure 11. Servers View: Launch the application by right clicking on the project and executing "Debug As".

For Further Consideration
The M2Eclipse plugin not only works nicely, but it can also integrate well with WTP. However, this integration does require some configuration even for web application projects as simple as this example used in this article.

The following are some additional tips to keep in mind when integrating M2 and WTP with the techniques described in this article:

  1. There is no need to maintain the .classpath file, nor is there a need to use the eclipse:eclipse goal that was used previously with the Maven Eclipse plugin. The .classpath is much cleaner because the pom.xml is used as a valid metadata for understanding the individual jars. All the referenced jars from the repository don't show up in the .classpath.
  2. The key to doing a WTP and M2 integration is to understand folder structures, Java build path settings, and the file .settings/org.eclipse.wst.common.component.
  3. You can learn everything about the actual application that you deployed by examining the folder .metadata\.plugins\org.eclipse.wst.server.core\ inside the workspace. You will need to explore the subfolders to locate the actual location where the web application is being assembled when you execute "Run on Server". A close look at it reveals that the servlet-api jar and the JUnit jar are not inside the assembled application's WEB-INF/lib folder, because they had scopes of provided and test, respectively. The earlier builds of the M2 plugin had an issue in this regard.
  4. If you use Maven 2, you don't need MAVEN_HOME or any other environment variable except JAVA_HOME and the correct path. And you need those only for executing Maven 2 from the command line.
  5. The M2 plugin uses a component of Maven called Maven Embedder. Embedder has been used by the Maven command line interface (CLI) since version 2.1.
  6. You must use Maven from the command line as part of continuous integrations and a regular non-IDE based build process. When running Maven from the command line to build and deploy the web application into Tomcat, refer to the Maven 2 documentation and the Maven 2 book Better Builds with Maven.

Raghuraman Ramaswamy is a senior consultant at Xebia IT Architects with seven years of J2EE development experience. He is a Sun-Certified Java Programmer and Business Component Developer.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date