Launching the Web Application from WTP
Now let's test the debugging functionality:
- Put a breakpoint in the servlet doGetMethod.
- Launch the application by right clicking on the project and executing "Debug As" (see Figure 10).
- Select "Debug on Server".
- 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 servletor, 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:
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.