Use eclipse as the development environment of Jakarta Tomcat

Source: Internet
Author: User
Use eclipse as the development environment of Jakarta Tomcat
Source: chinaitlab collection
2004-8-17 11:10:00
 
  Download Components
When setting the environment for eclipse and tomcat to work together, you need to use several components. See table 1.
  
   Table 1. components used in this article and their version numbers
    
Download the required components. The references section of this article lists the sites that can download these files. These sites are also accessible when published in this article.
  
Eclipse IDE: Eclipse IDE is used as the development environment for JSP pages and java files. Eclipse is a very simple and easy-to-use IDE environment with many features that can help programmers quickly write and debug Java programs. After the Tomcat plug-in is added, this IDE is an excellent tool for managing the entire web project (including HTML and JSP pages, icons, and servlets.
  
Sun SDK: an SDK required for Tomcat Eclipse plug-in to work properly. This SDK may not be Sun SDK, but must be an SDK (not a JRE, because it cannot work normally ). To enable tomcat to work normally with Eclipse, a Java compiler is required in the SDK.
  
Tomcat: Tomcat is required to drive the JSP page. Tomcat is a very good servlet engine, which can be freely downloaded and easily installed.
  
Sysdeo's eclipse Tomcat startup plug-in: This is one of the many Eclipse plug-ins used for Jakarta Tomcat. This is a very good plug-in, which saves me a lot of time and can be well integrated with web projects and Java code. I usually use eclipse to write these code.
  
  Install
Decompress all components
After downloading the required components, the next step is to decompress each file. Decompress these files and put them all in the same directory, so that you can find all the decompressed files.
  
Copy the Tomcat plug-in to the eclipse/Plugins directory.
After all the files are unzipped, copy the Tomcat plug-in directory to the Plugins subdirectory In the eclipse directory. The directory name I extracted from the sysdeo ZIP file is com. sysdeo. Eclipse. atat_2.2.1. Copy the entire directory to the eclipse/Plugins directory.
  
Install SDK
Next, install the downloaded SDK. The Eclipse plug-in of Tomcat requires that the JRE set in the eclipse workspace be a real SDK with a Java compiler. This is a requirement for using the sysdeo Tomcat plug-in. After installing the SDK, you can start the eclipse workbench.
  
The default JRE of eclipse must be from an SDK
The Tomcat plug-in requires that the default JRE set by eclipse be an SDK, otherwise the Tomcat plug-in will not work properly.
  
  Configuration
Set the JRE of This SDK to the default JRE of Eclipse.
Before starting eclipse, You need to configure some options on the preferences page of the workbench. Select WINDOW> preferences to open the preferences dialog box, as shown in 1.
  
   Figure 1. Eclipse preferences dialog box
    
Select the Java option in the Tree View on the left. Expand the Java element and select installed JRE, as shown in figure 2.
  
   Figure 2. JRE preference settings
    
Click "add" and switch to the JRE directory installed in the installation phase configured above, as shown in 3. Click "OK ".
  
   Figure 3. Add a JRE to the preference settings of eclipse
    
Select the check box on the edge of the JRE added during SDK installation, as shown in figure 4. In this way, set JRE to the default JRE used by eclipse. The Tomcat plug-in works only when this step is set correctly. The Tomcat plug-in requires that the default JRE selected in these settings be an SDK.
  
   Figure 4. Set the default JRE for eclipse and tomcat
    
Set Tomcat home variable in Tomcat preferences
Next, set the preferences of the Tomcat plug-in. The preferences dialog box is still displayed. Select "Tomcat" from the menu on the left, as shown in Figure 5.
  
   Figure 5. Set preferences of the Tomcat plug-in
    
Select the tomcat version from the preceding single-choice button. The tomcat version I use is 5.0.16, so select the last single-choice button "version 5.x ".
  
You must set the Tomcat home variable. Click the "Browse" button on the side of the "Tomcat home" dialog box to browse the root directory of Tomcat that was just extracted, and then click "OK. The configuration file is automatically selected and the corresponding content is added in the dialog box. If you want to select a different configuration file for Tomcat, you can browse these files now. Otherwise, the default value is used normally.
  
Now we have implemented the minimum requirements for using the eclipse and sysdeo Tomcat launcher plug-ins to start and run tomcat. View other Tomcat parameter settings in the following eclipse preference dialog box. Note that many other options are available in Tomcat parameter settings. For example, you can add a parameter to the JVM used by the Tomcat server, select a Java project from the workspace to add it to the Tomcat classpath, and perform some settings to allow tomcat to manage applications.
  
Test both Tomcat and eclipse
  
  Create a new Tomcat Project
To perform integration tests on Tomcat and eclipse, you can start by creating a new project. Select File> New> project and check the wizard content of the new project. There is a new project "Tomcat Project" in the Java section of the Project Wizard (see figure 6 ). Select this option and click Next.
  
   Figure 6. Create a New Tomcat Project
    
Name the new Tomcat project. For example, "atatproject", 7. Click Next.
  
   Figure 7. Set the Tomcat project name
    
Now we can see that you can specify the name for the context of the web project, and you can also specify a sub-directory as the root directory of the Web application. Now we keep the default value unchanged (see figure 8 ). Click Finish.
  
   Figure 8. Set the root directory of the Tomcat web application
    
A project with a war structure is created in the workspace, as shown in figure 9.
  
   Figure 9. Created Tomcat Project
    
Create a JSP file for testing
The easiest way to test the installation process is to create a new file in the root folder of the War Project. Create a new file, which is called "index. jsp ". To implement this function, select your project in the workspace and right-click it. Select New> file and name it "index. jsp", as shown in 10. Then click Finish.
  
   Figure 10. Create an index. jsp file to test the configuration
    
Add the content in Listing 1 to the index. jsp file and save the file.
  
Listing 1. index. jsp file example
<HTML>
<Body>
<% Java. util. Date d = new java. util. Date (); %>
  
Todays date is <% = D. getdate () %> and this JSP page worked!
  
</Body>
</Html>
  Use the sysdeo plug-in to start Tomcat
Now the great moment is coming. To start the Tomcat server, simply click Start tomcat in the toolbar, as shown in Figure 11. You can also select the Tomcat menu in the main menu and then select start Tomcat ".
  
   Figure 11. Use the sysdeo plug-in to start the Tomcat server
    
The Tomcat server will be started now, And the startup text will be displayed in the console view of the eclipse workbench, as shown in 12. Check the startup log and check for any errors.
  
   Figure 12. Tomcat startup information displayed in the eclipse console View
  
Start the browser and view the index. jsp file
After the server is started, start a web browser. Go to the URL http: // localhost: 8080/atatproject. A page is loaded, and you will see a message similar to the following:
  
Todays date is 30 and this JSP page worked! (The date displayed on my screen is 30, because today is the 30th .)
  
  Conclusion
Now you have correctly configured eclipse and configured it so that it can work with Jakarta Tomcat. Now we can quickly develop and test the integration of JSP and Java code. This excellent program can improve our productivity. Using eclipse to write Java code and integrate it with Jakarta Tomcat makes JSP development more interesting and easier.
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.