The deployment of J2EE applications is a very meaningful thing for deployers. Existing application servers generally support application deployment based on the Web, hot deployment, or through deployment tools. WebSphere Application Server 5.x provides an application programming interface to implement the deployment and management of J2EE applications.
1. WebSphere deployment overview
In general, to deploy a J2EE-based application, you need to do the following things: first, create a data source, in which the JNDI name needs to be specified; second, modify the resource JNDI name and resource reference of the enterprise application .ear file; third, modify the enterprise application. The EJB JNDI name and reference of the ear file; fourth, automatically deploy the modified enterprise application .ear file. Finally, restart the WebSphere server.
If these steps are completed manually, it can basically be completed quickly when there are not many EJB components, resource references and reference references. However, just imagine, if the same set of applications is to be run on the same WebSphere application server, and the EJB components, involved JNDI name modifications and resource (reference) modifications are many, we need to use the program to automatically The entire process is complete. The process can be well handled with the help of the Java interface (based on JMX technology) provided by WebSphere. Here the general process is given based on the deployment process (because the whole process is relatively complicated, only the main ideas are given here).
2. Automatic creation of data sources
This process will mainly involve the following aspects:
First: Find out the data source on the WebSphere server and see if its name conflicts with what we will configure.
Second: If not, then our program creates the required data source.
Third: If the JDBC ProvIDEr of the data source to be created does not exist, it should be created before the first and second steps.
Through such a few steps, we can realize the automatic creation of data sources.
Sample code is given below:
Create AdminClient:
Locate an existing JDBC Provider:
Save the creation data source operation:
3. Automatic modification of J2EE applications (.ear)
This part can generally be completed through the following steps:
First: Modify JNDI related content.
Second: Get the AppDeploymentTask task.
Third: Save the AppDeploymentTask task.
Fourth: Modify web-context. It can be accomplished using JAXP, JDOM, etc.
4. Automatic deployment of J2EE applications (.ear)
This part can generally be completed through the following steps:
First, implement NotificationListener.
Second, deploy the .ear application.
Implement NotificationListener:
In this way we achieve automatic deployment of J2EE applications. ■