) Replace Tomcat 5.x with glassfish v2

Source: Internet
Author: User
Tags touch command glassfish
Replace Tomcat 5.x with glassfish v2

1. Background

 

After using Tomcat for many years, no matter whether it is a development environment or a production environment, we should say that everyone is basically satisfied with it.
However, there is no problem at all. From the developer's point of view, the main disadvantage of Tomcat is its weak hot deployment.
(Hot deploy) capability. modify a Java class. After saving, Tomcat will re-load this class, but it will soon be re-loaded
Only when Tomcat is started can development be continued.ProgramIt is obviously inconvenient to correct the defects so that many users can stop their work and wait for the server to restart.

 

Similar to the technical framework of rubyonrails, it is convenient that the script language should not be compiled and can be used directly after being saved.
JavaCommunityObviously, the hot deployment capability of glassfish V2 is one of the most popular ones.
Feature. This is also the main reason for replacing Tomcat 5.x with glassfish V2.

 

2. Environment

 

This document assumes that you use the development environment described below.
(1) JDK 1.5 or 1.6
(2) Eclipse IDE for Java EE developers (3.3.1.1 M20071023-1652)
(3) Use the com. sysdeo. Eclipse. atat_3.2.1 plug-in

 

If you are not using eclipse 3.3.1.1 Java EE, but are using another version, it does not affect all the operations and effects described in this article, but you cannot start or stop glassfish V2 with eclipse, you can only perform operations by yourself through the command line.

 

For detailed instructions on using eclipse 3.3.1.1 Java EE to operate glassfish V2, seeEclipse 3.3 and glassfish Java ee 5 integration.

 

3. Download and install glassfish v2

 

This information can be easily found on the Internet.ArticleAs follows:
(1) deploy Web applications on glassfish
(2) glassfish preliminary test
(3) from tomcat to glashfish (installation startup notes for glassfish)

 

4. Create a tomcat Project

 

I believe you will also know how to create a tomcat project. This article assumes that you have created a tomcat project:
(1) In the D:/sample directory.
(2) The context name is sample.

 

Others are set by default.

 

5. To test the hot deployment capability of glassfish V2, create the homepage JSP and Servlet Java classes.

 

Step 2: Create the index. jsp file in the root directory

 

Step 2: create a simple servlet class sampleservlet. Java in WEB-INF \ SRC,

 

Step 2: configure the Web. xml file.

 

For the complete sample project, see the attachment.

 

6. What is glassfish V2 directory deployment?

 

When Tomcat is used for development, JSP, HTML, JS, CSS, and other files are modified and saved, and can be used after refreshing the browser.
To make glassfish V2 achieve the same effect, you need to use its directory deployment feature.

This feature is not easy to find, because developers who use full-featured application servers such as glassfish are used to it.
"Edit, compile, deploy, and run"Eclipse 3.3 and glassfish Java ee 5 integration.
After modifying the JSP file, you still need to go through the above deployment process.
Changing the file version triggers ant task deployment, but it is still a waste of time. We need to find a way to skip "deployment.
I posted several posts on the glassfish official forum, but the reply from the respondent did not play any role.
The problem has been resolved.

 

The following article guides me forward in the right direction (Thank you very much ):
Glassfish auto deployment and hot deployment

 

For more information about directory deployment, see:
Sun Java System Application Server Platform Edition 9.0 Application Deployment Guide
Deployment for development in Chapter 1

 

7. Implementation of glassfish V2 directory deployment

 

Step 2: Start glassfish V2.

 

Step 2: deploy the sample project to glassfish V2. Run the following command in the DOS window:

Java Code
    1. Glass_fish_home/bin/asadmin deploydir D:/sample
 
Glass_fish_home/bin/asadmin deploydir D:/sample

 

Here, glass_fish_home is the installation directory of glassfish. After the command is executed, you can see the successful deployment information.

 

Step 2: Open the browser and enter http: // localhost: 3rd/sample/index. jsp to view the page content.

 

Step 2: Open the browser and enter http: // localhost: 4th/sample/servlet/sample to view the page content.

 

8. Experience the hot deployment feature of glassfish v2

 

Step 2: modify the content of the index. jsp file. Save the file and refresh the browser to view the new content immediately.
(Http: // localhost: 8080/sample/index. jsp)

 

Step 2: Modify sampleservlet. java. After saving, wait for a moment. eclipse has automatically compiled this class, but there is no prompt on the glassfish V2 console. Refresh the browser and no new content is displayed.
(Http: // localhost: 8080/sample/servlet/sample)

 

Step 2: Now, create a file named ". Reload" in the root directory of the sample project (the content is blank ).

 

Step 2: Observe the glassfish V2 console and refresh the browser.


(Http: // localhost: 8080/sample/servlet/sample)

New content.

 

Step 2: modify the content of sampleservlet. Java again. After saving the content, you will encounter the same problem as step 3.

 

Step 2: Open the. Reload file again, enter any content, and save.

 

Step 1: the same effect as step 3 is displayed again.

 

To sum up the above operations, glassfish V2 achieves the same effect as Tomcat when loading non-Java classes.
The time stamp of the. Reload file must be used to control the loading. This method is good for development and can be modified during debugging and error correction.
Multiple Java class files, and then let glassfish V2 load all repaired classes at a time.

 

9. Automatic Reload file timestamp refresh

 

In the previous section, manually open the. Reload file and refresh its timestamp by modifying its content. This is too troublesome.

On Unix/Linux, run the touch command to refresh the timestamp of The. Reload file.
People have implemented touch. I found a touch.exe ON THE codeproject Website:Touch for Windows-the Code project-free tools,Easy to use, and can be integrated into the eclipse toolbar button to execute the touch command (Touch.exe is included in the attachment).

 

Step 2: copy the downloaded touch.exe file to the root directory of the sample project.

 

Step 2: Under eclipse, select Run> external tools> open external tools dialog.

 

Step 2: select the program node on the left, right-click it, and select the new menu item.

 

Step 2: Fill in the following content in the displayed dialog box on the right


Name: sampletouch
Main [Page]
Localtion :$ {workspace_loc:/sample/touch.exe}
Working directory :$ {workspace_loc:/sample}
Arguments:. Reload
Common [Page]
Display in favorites menu: select external tools

After saving, you can see the newly created item in the eclipse run toolbar button.

 

10. Conclusion

 

Using glassfish V2 can completely replace Tomcat 5.x, which retains the features of Tomcat during development.
At the same time, it brings us strong hot deployment features, significantly improving the development efficiency.

 

Thanks to glassfish V2 and the Java community members who have made us feel the technology.
The joy of progress.

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.