Use eclipse to develop J2EE Projects

Source: Internet
Author: User
Tags apache tomcat

 

Chapter 2 Introduction to eclipse 1.1 select eclipse to develop J2EE background and significance 1.1.1 backgroundEclipse, like many other Java ides, can be downloaded for free. However, there are great advantages behind eclipse, and IBM is back up, it is said that IBM spent more than 4 million dollars to develop this IDE. Eclipse is a universal tool platform. It can be used for development in Java, C #, JavaScript, and other languages. The entire Eclipse project is divided into three sub-projects: the eclipse platform, which is the backbone of the entire program. Ø Java Development Project Toolbox (Java Development Tookit, jdt ). Ø plug-in Development Environment (PDDE ). Allows users to develop tools for Eclipse, called plug-ins ). These sub-projects are further divided into other sub-projects. For example, the jdt sub-project consists of user interface (UI), core, and debug) sub-projects. Http://www.eclipse.org has a detailed introduction to these subitems. 1.1.2 running condition eclipseEclipse is written in Java, but the downloaded package does not contain the Java Runtime Environment. You need to install JRE separately, in addition, specify the bin path in JRE in the environment variable of the operating system. Currently, the latest JDK version is 1.5.0, you can download to the http://java.sun.com. I downloaded j2sdk-rj4_2_5-windows-i586-p.exe. Currently, this version is universally accepted and stable. The installation process is also very simple, double j2sdk-00004_2_5-windows-i586-p.exe, first a interface will appear to check the system environment. After the installation is completed, the following installation welcome page will appear: Select next and select the installation path you want to install. My installation path is C:/j2sdk1.4.2 _ 05; the installation is generally completed within five minutes. The following describes how to set the JDK environment variable. For example, in Windows 2003, a similar picture is displayed on my computer named "à ". Click "CREATE, enter the following values in sequence, as shown in figure. The configuration is as follows: ø java_home = C:/j2sdk1.4.2 _ 04; the root directory of JDK installation. Ø Path = % java_home %/bin; ø classpath = .; % java_home %/lib/DT. jar; % java_home %/lib/tool. jar to enter the Windows Command Prompt interface, enter Java, and press Enter. If the following screen appears: indicates that JDK is successfully installed! 1.1.3 obtain eclipseEclipse is an open source project, you can go to the http://www.eclipse.org to download the latest version of eclipse for free, general eclipse provides several Download versions: release, stable build, integration build and nightly build, we recommend that you download the release or stable version, select the appropriate operating system and the latest version, and then select the appropriate link to download. The steps for installing eclipse are very simple: you only need to extract the downloaded package directly from the original path. Note that if an updated version is available, you must delete the old version and reinstall it. You cannot directly decompress the package to overwrite the old version. If you need to install two or more versions of Eclipse, You can decompress them to different folders. After Uncompressing the file, you can find the corresponding installer to run eclipse.exe. If the downloaded version is release or stable and the JRE environment is correctly installed, there will be no problems in general. After a cool eclipse image is flashed, eclipse will display its default Interface, indicates that eclipse is successfully installed and can be used. 1.1.4 platform eclipseThe eclipse platform consists of the platform kernel, workbench, workspace, Team component, and help component components ). It indicates the overall design structure of Eclipse. 1.2 install and test TomcatFor web development, you must have a web server to deploy and Debug programs. Fortunately, we have a series of related open-source servers for J2EE development. Apache Tomcat is widely used. Apache Tomcat is a standard implementation based on Servlet/jsp specifications and can be easily competent for most J2EE development and debugging. You can download the Tomcat web server from http://jakarta.apache.org/tomcat. Currently, the latest version of Tomcat is 5.5.17. Most of our current J2EE application development programs still follow the servlet/jsp specification 2.3/1.2. Based on this, I chose Tomcat 4.1.31 as the web development and testing server. Click http://jakarta.apache.org/tomcatto select the region of your operating system, and then select the link to download. The installation of Tomcat 4.1.31 in Windows is very simple. The following is a brief introduction: the prerequisite for installing Tomcat 4.1.31 is to install JDK. I have discussed the installation process before, see 1.1.2 eclipse running conditions. Double-click the downloaded jakarta-tomcat-4.1.31.exe and you will see the following welcome page: select the I agree button to go to the next page, enter the Tomcat pre-installed root directory, and click the Install button to start installation. After the installation is complete, go to the Tomcat root directory to get the following directory structure: for Web developers, the most important directory is webapps, and the files to be read by the browser are stored here. In Windows, enter "Startup" to start Tomcat; in UNIX, run startup. Sh to start Tomcat. In Windows, a new DOS window is opened, showing the initial settings. When you want to disable tomcat, input "shutdown" in windows, and run shutdown. Sh in UNIX. Note: You can find various methods to start Tomcat in the running.txt file attached to Tomcat. Now Tomcat is running. Open the browser and connect to http: // localhost: 8080. If you see the following welcome page of Tomcat, it indicates that Tomcat is successfully installed. Chapter 2 J2EE Project Development 2.1 integrate Tomcat eclipse 2.1.1 download the eclipse Tomcat plug-inSysdeo plug-in allows you to start and stop tomcat in eclipse environment. I want to talk about this plug-in here. You can download this plug-in from http://www.sysdeo.com/eclipse/tomcatPlugin.html for free. 2.1.2 install eclipse Tomcat plug-inDecompress tomcatpluginv2.zip and copy the com. sysdeo. Eclipse. Tomcat folder to the Plugins directory under the eclipse installation directory. Expand the Plugins directory, select "Windows" à "mimize perspective", open the "other" node, select the "Tomcat" project, and start it. 2.1.3 ConfigurationStart eclipse. Open the menu windows. preferences. Select Tomcat on the left. Some forms are displayed on the right. Select tomcat version 4.0.x. Select tomcat installation path for Tomcat home, configuration file will automatically fill in the tomcat configuration file context files ø expand the Tomcat menu on the left, select JVM settings, select detected Vm for jre. Press Apply. Press OK to check if there are several more kitten icons in your toolbar. If not, select windows à custmize perspective and expand the other option, check tomcat. OK. No kitten icon is displayed. Ø try the start Tomcat button. Now, Tomcat is started on the console. The specific configuration page is as follows: 2.2 create a project in eclipseSelect File à create a project. In the displayed dialog box, select Tomcat project and click Next. Then, click Finish. 2.3 file organization hierarchy of the eclipse Development ProjectIn the J2EE project, the structure, library, JSPs, and compiled classes exist in different branches of the directory tree. The servlet specification defines. the war file is saved in the following structure: + JSPs/---- WEB-INF | ---- web. XML | ---- classes/---- lib can be seen that this can probably adopt a better project structure organization method similar to this. Eclipse supports debugging to start Tomcat on the application server in IDE. Therefore, most J2EE applications developed by ECLIPSE use the following project directory structure: + project | ---- build | ---- test | ---- docs | -- requirements | -- mockups | ---- lib (previously lib/buildtime) /---- SRC | ---- Java | ---- test/---- webapp/---- WEB-INF | ---- classes (previusly build/Java)/---- lib (previusly lib/runtime) follow this idea, in conjunction with the first test project, this article describes how eclipse can build an organizational structure based on this file. Right-click the first project and select properties. The Properties dialog box of the Fisrt project is displayed. Select the Java build path option. In the displayed dialog box, select the source code tab and click Add folder to create the first project source code tree. As shown below, the source code tree is built. According to the similar operation, you can import the jar package required by the first project, as shown in the following figure. Once the source code tree is built. The next task is to build the location of the deployment file. In eclipse, you can see the attribute Tomcat option of the first project. Click it to display, as shown in, the text box corresponding to the context name is the name of our first application. when accessing the context name in a browser, the content in the address bar is as follows: http: // localhost: 8080/first, you can access this application. The input box corresponding to subdirectory to set as Web application root (optional) enables the Tomcat server to find our web files. Based on the content entered in the preceding dialog box, the Tomcat plug-in of eclipse generates first. xml under Tomcat's webapps to describe the deployment of the first project. 2.4 eclipse development JSPThe following uses a small instance to demonstrate the simplicity and convenience of using eclipse to develop J2EE projects. Using eclipse to compile JSP files that do not need to be compiled is the simplest. These files can include the Java package in the "small script element", "Declaration element", and "expression element ). The most common is the small script element, which can be used to package several lines of Java. The beginning and end of a script element are two types of markup symbols: <% "and" %> ", as shown in Example 9-1. You can use the println () method of the out object to send the text back to the browser. In this example, we only send the text "Using JSP" back to the browser in this JSP. Example 9-1: JSP
<HTML>
This section of code is shown as follows in Eclipse: Start the Tomcat plug-in because the deployment file has been set up above. Therefore, in IE, we can directly access the content displayed on this JSP page. Although simple, it is enough to show how convenient it is to use eclipse to develop and deploy J2EE applications. The page is as follows:
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.