Myeclipse tomcat configuration + Test details (excluding eclipse)

Source: Internet
Author: User

Myeclipse Tomcat is no stranger to Java programmers, But how do they configure it? This is a learning difficulty for beginners. This article will introduce you to the configuration of myeclipse tomcat.

I. Software Installation and Registration

Install JDK first. Here I use D: \ Program Files \ Java. There are two folders: JDK and JRE. If you want to set a classless path, go to the Internet to find relevant materials. Many articles have been mentioned.

For tomcat installation, we use the installation file of the EXE version. Except for the Directory selected, all the other files are installed by default. Here we install them to D: \ tomcat6.0. Note that the space in the middle is removed, it is troublesome to have spaces. (For tomcat configuration, see my other article)

Myeclipse is an EXE installation file. If you have an installation wizard, double-click the installation and select the eclipse Installation Directory D:/eclipse. (Note: you do not need to select a new version because it comes with eclipse) and its own installation directory (decided by yourself), here use D: \ myeclipse \ eclipse, and then one way to next.

In the program group, we can find the myeclipse program group and click open. If you do not have a default working path, select a working path and you will see a typical eclipse interface integrated with myeclipse.

Enter the registration code of myeclipse, open the menu window-> preferences, open the myeclipse-> subferences item in the menu tree of the dialog box, click Enter subferences... Enter the user name and password.

 

2. Configure tomcat in myeclipse

1) Myeclipse-> Windows->Preferences-> JAVA-> installed jres

        Check whether it is empty If it is null, manually add a JDK installed on the machine

2) choose myeclipse> Windows>Preferences-> myeclipse-> servers->Tomcat 6.x  

        Tomcat server is enable;

        Tomcat Home Directory: D: \ Tomcat 6.0; (tomcat installation path)

        TomcatBase Directory: D: \ Tomcat 6.0

         TomcatTemp Directory: D: \ Tomcat 6.0 \ Temp;

3) myeclipse-> Windows->Preferences-> myeclipse-> servers->Tomcat 6.x-> JDK 

        Set it to the default or self-installed JDK

4) myeclipse-> Windows->Preferences-> myeclipse-> servers->Tomcat 6.x 

-> Launch  

         Set Tomcat launch mode to run Mode

 

3. Create a WEB Project

OK. All the required software has been installed and configured. Let's create a simple project to describe the application of myeclipse.

Because only the basic operations and settings of myeclipse are described here, no complicated project is involved, and you can bypass the similar project.

1. Open the myeclipse development interface, file-> New-> projects ..., Open the Create Project dialog box, find and select Web project, click Next, and enter webtest in the projects name of web project details. The default value is used for other items. Note that the context root URL here is/webtest, otherwise, you must enter the corresponding name in IE to use it. Check whether the tag library is supported at the bottom. Choose jstl1.1. Click Finish to create the project.

We can see that the classes required for the new project have been automatically loaded, and there is also a J2EE class environment variable, which is the convenience of using myeclipse.

2. Create a hello class

3. Select the SRC folder under the project webtest (Note: If this folder cannot be found under package explorer, go to the eclipse User Guide, window-> show view-> package Explorer), right-click the New-> package menu, and create a new package COM. specified resky. bean. Select the new package, right-click New-> class, and enter hello in name to remove the public static void main option. All others are default. Click Finish to create the class.

The Edit class code is as follows:

 
 
  1. package com.inspiresky.bean;  
  2.  
  3. /*   
  4. * Junsan   
  5. * http://www.inspiresky.com/bbs   
  6. public class Hello {   
  7. private String message = "Hello World";   
  8. /**   
  9. * @return Returns the message.   
  10. */   
  11. public String getMessage() {   
  12.         return message;   
  13. }  
  14.  
  15. /**  
  16.  
  17. * @param message The message to set.   
  18. */   
  19. public void setMessage(String message) {   
  20. this.message = message;   
  21. }   
  22. }  

Note that the bean attribute operation method can define the attributes first, and then right-click the menu source-> Generate getters and setters in the editing window, in the dialog box, select the property of the get and set methods to be generated to confirm.

4. Create a JSP page

In the webtest project, select the webroot folder, right-click the menu New-> JSP, and change the file name to index. jsp. By default, click Finish to create the folder.

Edit the content of the JSP file as follows:

 
 
  1. ﹤%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%﹥  
  2.  
  3. ﹤%   
  4. String path = request.getContextPath();   
  5.  
  6. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";   
  7.  
  8. %﹥   
  9.  
  10. ﹤jsp:useBean id="hello" class="com.inspiresky.bean.Hello" scope="page"/﹥   
  11.  
  12. ﹤jsp:setProperty name="hello" property="message" value="Hello World!" /﹥   
  13.  
  14. ﹤!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"﹥  
  15.  
  16. ﹤html﹥   
  17.  
  18.     ﹤head﹥   
  19.       ﹤base href="﹤%=basePath%﹥"﹥  
  20.  
  21.       ﹤title﹥My JSP 'index.jsp' starting page﹤/title﹥  
  22.  
  23.        ﹤meta http-equiv="pragma" content="no-cache"﹥   
  24.       ﹤meta http-equiv="cache-control" content="no-cache"﹥  
  25.  
  26.       ﹤meta http-equiv="expires" content="0"﹥  
  27.  
  28.       ﹤meta http-equiv="keywords" content="keyword1,keyword2,keyword3"﹥  
  29.  
  30.       ﹤meta http-equiv="description" content="This is my page"﹥   
  31.       ﹤!--   
  32.       ﹤link rel="stylesheet" type="text/css" href="styles.css"﹥  
  33.  
  34.       --﹥   
  35.     ﹤/head﹥  
  36.     ﹤body﹥   
  37. ﹤jsp:getProperty name="hello" property="message" /﹥﹤br﹥   
  38.       This is my JSP page. ﹤br﹥   
  39.     ﹤/body﹥  
  40.  
  41. ﹤/html﹥ 

5. Configure the Tomcat server (which has been configured above = can be ignored)

Eclipse menu, window-> preference ..., Open the preference dialog box and find myeclipse-> application servers-> Tomcat 6 in the menu tree. Select five Tomcat items. In the dialog box, select the Enable single-choice button, click the Browse button in the Tomcat home directory input box, and select the installation root directory of Tomcat. Here is D: \ tomcat6.0, other boxes are automatically filled. Click Apply.

Select JDK in Tomcat 6. Note that the default runtime environment is JRE. Set JDK here. Otherwise, myeclipse cannot be a web application, the Tomcat server cannot run normally.
Select installed jres from Java.
Click the Add button, write JDK 1.5.0 _ 06 to the JRE name, and select the JDK root directory in the Browse selection box. Here is c: \ Program Files \ Java \ jdk1.5.0 _ 06, for other default values, click OK. In Tomcat JDK name, select the one we just created, that is, jdk1.5.0 _ 06. Click the Apply button and click it every time. Sometimes there is a problem with eclipse. If you do not click this button to go to another configuration page, the above configuration will be lost.

Make sure that the debug mode is selected in the launch of Tomcat 5.

In paths, there are some class path settings. The first is the class path that is loaded in advance. Some packages will be used when the server is started to initialize the web application; the second is used only during running; the third is the class without packaging, so we don't care about it here.

Now you can click the OK button in the preference dialog box to complete tomcat configuration.

6. Subordinate Web Applications

This is simple. Select the root directory of the webtest project, right-click the menu myeclipse-> add and remove projects deployments ..., In the displayed dialog box, make sure that projects is webtest. Click Add. In the displayed dialog box, select Tomcat 5 as the server. The following two single options are displayed, exploaded archive and packaged archive are directory-based subordinates and package-based subordinates, which are all made by myeclipse. We use directory deployment instead of war packages. Click finished to return to the previous page.

If the server is specified, deploy the Application below. Select the five Tomcat items in the server list in the dialog box. The gray button becomes available, and the remove and redeploy buttons remove deployment and redeploy. Click redeploy, you can click this button to redeploy the modified project. Click here.

OK. The program has been deployed. Run and debug the program below.

7. Run the debugging program

In the eclipse graphic menu bar, find (the "Redeploy" button on the left and the "self-dropping" browser on the right), click the drop-down button, select Tomcat 5, and click the "Start" menu to start Tomcat.

When the Consol window prompts that Tomcat is successfully started, we can run our program. Open an IE browser window and enter http: // localhost: 8080/webtest/. The following information is displayed:

 
 
  1. Hello World!  
  2. This is my JSP page. 

The operation is successful.

Next, let's talk about debugging. At this time, it's the same as normal debugging, with a breakpoint added. JSP files and class files can be debugged in one step.

Open the hello. Java edit box and add a breakpoint in the return message; line. Refresh the IE window, And the eclipse window will appear, stopping at the breakpoint. Press F8 to delete the breakpoint.

In the edit box of the index. jsp file, go to <JSP: getproperty name = "hello "... /> Place a breakpoint on a row and refresh the IE window. Then, go back to the eclipse editing window and check that the cursor has stopped at the breakpoint line.

You don't need to talk about other debugging. You only need to use eclipse to check the attribute status value and the like. It is the same as debugging in time.

I will introduce you to the configuration of myeclipse tomcat, and hope to help you.

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.