The deployment of Java EE applications is a significant thing for the deployer. Existing application servers generally support the deployment of applications based on the Web, or hot deployment, or through the deployment of tools. WebSphere Application Server 5.x provides an application programming interface for deployment and management of Java EE applications.
A. WebSphere Deployment overview
In general, there are a few things you need to do to deploy an application based on Java EE: First, create a data source where you need to specify a jndi name; Second, modify the resource Jndi name and resource reference of the enterprise application. ear file; Third, modify the EJB Jndi name and reference reference of the enterprise application. ear file; Finally, automatically deploy the modified enterprise application. Ear file. Finally, restart the WebSphere server.
These steps, if done manually, can be done almost quickly in situations where the EJB component is not many, resource references, and reference references are not many. But imagine that if the same set of applications were to run on the same WebSphere application server, and the EJB components involved, the Jndi name modifications, and the resources (references) were modified a lot, we would need to automate the process with the help of the program. The Java interface provided by WebSphere (based on JMX technology) can handle the process well. Here is a general process based on the deployment process (because the whole process is more complex, here is just the main idea).
Ii. automatic creation of data sources
This process will mainly cover the following aspects:
First: Identify the data sources that are available on the WebSphere server and see if their names conflict with what we will configure.
Second: If not, our program creates the data source that you want.
Third: If the JDBC provider for the data source you are creating does not exist, you should create it before step first to second.
With such a few steps, we can realize the automatic creation of the data source.
Here's how to show the sample code:
创建AdminClient:Properties props = new Properties();
props.setProperty(AdminClient.CONNECTOR_TYPE,
AdminClient.CONNECTOR_TYPE_SOAP);
props.setProperty(AdminClient.CONNECTOR_HOST, ipAddress);
props.setProperty(AdminClient.CONNECTOR_PORT, port);
AdminClient adminClient =
AdminClientFactory.createAdminClient(props);
定位现有的JDBC Provider:
ConfigService configService = new ConfigServiceProxy(adminClient);
Session session = new Session();
ObjectName[] provider = configService.resolve(session,
"Cell=" + cell + ":Node=" + node + ":JDBCProvider");
ObjectName db2Provider = null;
for (int i = 0; i < provider.length; i++) {
String jdbcProviderName = (String) configService.getAttribute(session,
provider[i], "name");
if (jdbcProviderName.equals("xxx JDBC Provider")) {
db2Provider = provider[i];
break;
}
}
To save the Create data source action:
Configservice.save (session, True);
Configservice.discard (session);