Web project debugging on Eclipse

Source: Internet
Author: User
Tags java web tomcat server apache tomcat

The first challenge in developing a Web project in Eclipse is how to debug code. This article briefly describes how to debug Java Web projects in eclipse using Tomcat and jetty.

Tomcat plug-in mode. eclipse itself can be debugged by downloading and installing the Tomcat plug-in, so there is no need to install the Tomcat server separately because the plug-in is integrated with Tomcat's running environment. The plugin url http://www.eclipsetotale.com/tomcatPlugin.html, plugin download address: http://www.eclipsetotale.com/tomcatPlugin/ Tomcatpluginv321.zip, the download is installed in eclipse as a normal plugin (copy or link). However, there are some differences between the debugging environment in this way and the real-world environment, and the running directory defaults to the eclipse's plug-in directory, the operating environment is not intuitive, so this is not recommended here.

Tomcat Server method. First Download installs Tomcat (address http://tomcat.apache.org/). Then open Eclipse and add Tomcat Server to eclipse. The steps are as follows:

Window->preferences->server->runtime environments->add-> Select Apache Tomcat v6.0->next-> Select the Tomcat installation directory->finish.

When Tomcat is added to Eclipse's server, Eclipse automatically creates a project called "Servers," which contains Context.xml, Server.xml, Tomcat-users.xml, Basic configuration files such as Web.xml. The following starts configuring the Web project Debugging options:

Right-click on the Web project->debug as->debug configurations-> Right-click on Apache Tomcat->new, create the debugger, and then use the default configuration option. You can then right-click on the project->debug on server to start debugging the Web project.

Jetty Server method. This configuration is similar to Tomcat. First or download the installation jetty (address: http://jetty.codehaus.org/jetty/). Then open Eclipse and add jetty Server to eclipse. The steps are as follows:

Window->preferences->server->runtime environments->add-> Select Jetty 6->next-> Select Jetty installation directory-> Next-> set Port->finish.

The following starts configuring the Web project Debugging options:

Right-click on the Web project->debug as->debug configurations-> on the generic server, right-click->new, create the debugger, and then use the default configuration option. (The JRE in the configuration information typically chooses the default JRE). You can then right-click on the project->debug on server to start debugging the Web project.

Jetty Debug Multiple Web projects. when projects are large, Web projects are often decomposed into multiple child Web projects, developed separately, and aggregated into a complete web system. Since a subweb project cannot be run independently, one of the problems with the decomposition development is debugging during development, jetty supports starting the Web server with the specified profile, and supporting a multiple-folder aggregation Web site, so you can configure jetty to solve this problem. When debugging, Jetty automatically merges the various subprojects that are distributed in different locations into a complete project logically. Configuration method:

First create the User Library:window->preferences->user libraries->new containing the jetty package (enter name jetty)->add jars-> Select the jetty packages to include in the jetty installation directory, which includes: {Jetty directory}/lib/ext/*.jar;:{jetty directory}/lib/jsp-2.1/*.jar.

When the project is decomposed, the Web project is decomposed into a primary Java Web project and several common Java projects, where the main Web project is used to coordinate file maintenance management and startup projects.

1. Right-click on the main Web project, select Debug As->debug configurations-> on the Java application right-click->new, and then start configuring the debugger:

2. In the tab "Main", set project options to be the primary Web project; Main class set to Org.mortbay.xml.XmlConfiguration;

3. In the "Arguments" tab, set the program Arguments to ${workspace_loc:xxxx}/jetty.xml, where xxxx is the primary Web project name, Working directory, " Other "option is set to ${workspace_loc};

4.Classpath tab, Bootstrap entries first adds the user Library that contains the jetty jar package created above, and then adds additional user Library,user for the project Entries to add the main Web project and all other child Java projects;

5. Add source projects that need to be debugged in source;

6. After the above configuration is complete, start to configure the jetty boot configuration file Jetty.xml, the above setting "${workspace_loc:xxxx}/jetty.xml" is to place jetty.xml in the root directory of the main Web project. The file can be copied from the Ext/jetty.xml folder in the Jetty installation directory, slightly modified. You can configure the storage path for the Web resource files in each subproject in Jetty.xml, or you can create a new Jetty-web.xml file in Web-inf to configure the Web resources in the subproject separately. Sample Jetty-web.xml:

<?xml version= "1.0"  encoding= "iso-8859-1"?>
<! DOCTYPE Configure Public "-//mort Bay consulting//dtd configure//en" "Http://jetty.mortbay.org/configure.dtd" >
<configure class= "Org.mortbay.jetty.webapp.WebAppContext" >
<set name= "BaseResource" ><new class= "Org.mortbay.resource.ResourceCollection" >
      <Arg>
        <array type= "java.lang.String" >    
          <Item>MainProject/WebContent</Item>     
          <Item>SubProject1/WebContent</Item> 
          <Item>SubProject2/WebContent</Item>  
         </Array>
      </Arg>
    </New>
  </Set>
  <set name= "ContextPath" >/vpath</Set>
</Configure>

Web projects typically contain jar reference packages, class files, Web resource files (JSP, JS, CSS, pictures, and so on), and jar files are configured in the bootstrap entries of the Classpath tab The class file is configured in the user entries on the Classpath tab, the Java source file is configured on the Source tab when debugging, and the Web resource file is configured in the Jetty-web.xml file. This allows jetty to start the complete Web project based on these configuration options.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.