Configuring MyEclipse and Tomcat

Source: Internet
Author: User

1. Installation and registration of software

First to install the JDK, I use the default installation, the directory does not change all, C:/Program Files/java, there are two folders below, one is the JDK, one is the JRE. To set the classpath and so on, please go to the Internet to find relevant information, that many articles said.

Tomcat installation, we use the EXE version of the installation files, in addition to the selection of directories, the other defaults are good, here to install to d:/tomcat5.5, pay attention to the middle of the space removed, because sometimes the space will be very troublesome.

Eclipse is easy to install, just unpack, and then place the unpacked file Eclipse folder in the appropriate installation directory, such as D:/eclipse. Find the Eclipse.exe file in the installation directory, start Eclipse, set the JDK and work path to see the Eclipse's Welcome page. We don't use eclipse here, so turn it off.

MyEclipse is an EXE installation file, there is the Installation Wizard, double-click the installation directly, select the Eclipse installation directory D:/eclipse and its own installation directory, where the use of d:/myeclipse/eclipse, and then all the way next.

We can find the MyEclipse program group in the program group, click Open, if you do not have the default work path, select a work path, you will see the integration myeclipse after the typical eclipse interface.

Finally, you need to enter the MyEclipse registration code, open the menu window->preferences, open the Myeclipse->subscription item in the menu tree of the dialog box, click Enter Subscription ... button, and then enter a registered username and password.

OK, all the required software is installed here, so let's create a simple project to illustrate the application of MyEclipse.

2. Create Web Project

Because here only explains the basic operation and the setting of MyEclipse, so, do not do very complicated project, completely can analogy.

Open the MyEclipse development interface, file->new->projects ..., open the New Project dialog box, select Myeclipse->j2ee Projects->web Project, click the Next button, in the Web project Details of the projects name in the input webtest, the other defaults, note that the context root URL is/webtest, otherwise, you will be in IE to enter the appropriate name to use. Note that the bottom of this is whether to join the tag library support, we choose JSTL1.1. Then, click the Finish button to complete the project creation.

We look at our new projects, the classes that are needed have been automatically loaded in, and a Java EE class environment variable, which is the convenience of using MyEclipse.

3, New Hello class

Select the SRC folder under the project WebTest (note that under Package Explorer, if this is not found, go to the Eclipse Usage guide, window->show view->package Explorer), Right-click menu New->package, create a new package Com.inspiresky.bean. Select New Package, right-click menu New->class,name Enter Hello, remove public static void main option, all other defaults, click Finish button to complete class creation.

Edit the code for the class as follows:

Package Com.inspiresky.bean;

/*
* Junsan
* Http://www.inspiresky.com/bbs
public class Hello {
Private String message = "Hello World";
/**
* @return Returns the message.
*/
Public String GetMessage () {
return message;
}

/**

* @param message to set.
*/
public void Setmessage (String message) {
this.message = message;
}
}

Notice how the bean properties are manipulated here, you can define the attributes first, then in the edit window, right-click the menu Source->generate getters and Setters, and then in the dialog box, select the property that you want to generate the get and set methods to determine.

4. Create JSP page

In the WebTest project, select the Webroot folder, right-click menu New->jsp,file name to index.jsp, other defaults, click the Finish button to create.

Edit the contents of the JSP file as follows:

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>

<%
String path = Request.getcontextpath ();

String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";

%>

<jsp:usebean id= "Hello" class= "Com.inspiresky.bean.Hello" scope= "page"/>

<jsp:setproperty name= "Hello" property= "message" value= "Hello world!"/>

! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"


<base href= "<%=basePath%>" >

<title> my JSP ' index.jsp ' starting page </title>

<meta http-equiv= "Pragma" content= "No-cache"
<meta http-equiv= "Cache-control" content= "No-cache"

<meta http-equiv= "Expires" content= "0"

<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3"

<meta http-equiv= "description" content= "This are my page" >
!--
<link rel= "stylesheet" type= "Text/css" href= "Styles.css"

-->
<body>
<jsp:getproperty name= "Hello" property= "message"/> <br>
This is the My JSP page. <br>
</body>


Notice the code that the Red section adds for us. Well, our code has been written.

5. Configure Tomcat Server

Eclipse menu, Window->preference ..., open the Preference dialog box and locate the Myeclipse->application Servers->tomcat 5 in the menu tree. Select Tomcat 5, in the dialog box, select the Enable radio button, and then click the Browse button in the Tomcat home directory input box to choose Tomcat's installation root, which is d:/tomcat5.5, and the other boxes are automatically populated. Click the Apply button.

Select the JDK in Tomcat 5, where you should pay special attention that the default is the runtime environment of the JRE, which is set to JDK, otherwise the myeclipse will not be able to subordinate the Web application properly and will not run the Tomcat server properly.

Enter the installed JREs preferred to Java.

We click the Add button, write jdk1.5.0_06 in JRE name, and then select the JDK root in the Browse selection box, which is C:/Program files/java/jdk1.5.0_06, the rest of the default, click OK button. Selecting the one we just created in the Tomcat JDK name is jdk1.5.0_06. Click on the Apply button, every time you click, sometimes eclipse problems, you do not click this run to another configuration page will lose the above configuration.

We made sure that debug mode was selected in the launch of Tomcat 5.

And paths is a number of classpath settings, the first is to load the class path in advance, some packets start the server to initialize the Web application to use, this is the second is the runtime to use, and the third is not packaged classes, here we will ignore.

Now you can click the OK button on the preference dialog to complete the configuration of Tomcat.

6, subordinate Web application

This is simple, we select the root of the WebTest project, right-click menu Myeclipse->add and Remove Projects deployments ..., in the Open dialog box to ensure that Projects for webtest, click the Add button, In the pop-up dialog box in the server select Tomcat 5, the following two single options, exploaded archive and packaged archive are directory-style subordinates and package way subordinates, this is done by the MyEclipse, we use the directory deployment method, No war packs, no more. Click the finished button to return to the previous page.

The server specifies that the application is deployed below. Select the Tomcat 5 item in the dialog server list, at which point the grayed out button becomes available, where the remove and redeploy are removed from the deployment and redeployment, we click the Redeploy button, and later we modify the project or click this button to redeploy. Here we can click on it.

OK, the program has been deployed, the following to run debugging.

7. Run the Debugging program

In the Eclipse's Graphics menu bar (the button on the left is the redeployment button, the right side is the browser), click the Drop-down button, select Tomcat 5, then click the Start menu to start Tomcat.

The Consol window prompts Tomcat to start successfully, so we can run our program. Open an IE browser window, enter http://localhost:8080/WebTest/, we can see the following information:

Hello world!
This is the My JSP page.

Indicates that the operation was successful.

The following is about debugging, hehe, this time and normal debugging like, plus breakpoints. JSP files and class files can be debugged as one step.

Open the Hello.java edit box, in return message; With a breakpoint on one line, we refresh the IE window, and the Eclipse window appears and stops at the breakpoint. Press F8 to finish and remove this breakpoint.

We open the Index.jsp file edit box, in <jsp:getproperty name= "Hello" .../> a line to hit the breakpoint and refresh the IE window. Then go back to the Eclipse editing window and the cursor has stopped at the breakpoint line.

Other debugging is needless to say, as long as the eclipse will know, look at the property status values and so on, and normal debugging is the same.

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.