Migrate WebLogic EJB program to JBoss

Source: Internet
Author: User
Tags jboss application server jboss server

WebLogic Server is a top-level commercial application server. However, for small-scale developers, the development source code-based, standard-based application server JBoss can be used to replace commercial application servers such as WebLogic or WebSphere. Unfortunately, applications developed in WebLogic cannot be deployed in JBoss. The JBoss Migration Service provides us with support for migrating applications to JBoss. Instead, by migrating the vendor-specific deployment file information to JBoss, the application may be migrated to JBoss. To demonstrate how to migrate an application to JBoss, We will migrate an EJB application with an Oracle database developed in WebLogic to a JBoss application server with a MySQL database.

  Pre-installed software

To configure the JDBC connection of the MySQL database, you need to download the MySQL database Driver Class.

1. Download the MySQL JDBC driver. jar File

2. download and install the MySQL database server

3. download and install the JBoss 4.0 Application Server

Develop a Java application. We will use it and XSLT to convert the WebLogic deployment file to the JBoss deployment file. The deployment file can also be converted using the XSLT tool.

  Overview

Without modification, the applications developed in WebLogic cannot be deployed in JBoss. The JBoss Application Deployment file is different from the WebLogic deployment file. In this article, we will migrate an entity EJB application sample developed in WebLogic to JBoss. The migration method is to convert the WebLogic deployment file to the JBoss deployment file.

The sample application contains a Catalog entity EJB. In the examples file. We will use the MySQL open source database to configure the JBoss application. Deploying WebLogic EJB applications to JBoss does not need to modify the entity EJB class. You only need to modify the deployment file of this EJB.

 Configure JBoss and MySQL

MySQL is an open-source database suitable for open-source projects and small organizations. To configure the JBoss and MySQL databases, you need to make the following changes.

 Configure JBoss class path

To use JBoss 4.0 and MySQL, we first need to copy the driver class. jar file (mysql-connector-java-3.0.9-stable-bin.jar) to the <JBoss>/server/default/lib directory. <JBoss> is the directory where the JBoss application server is installed. The. jarand. ZIP files in the libdirectory are included in the Classpath (class path) of the JBoss server.

  Configure the MySQL Data Source

To use the MySQL data source, copy the <JBoss>/docs/examples/jca/mysql-ds.xml to the <JBoss>/server/default/deploy directory. When the JBoss server is started, the data source configuration file in the deploy directory is deployed. Follow these steps to modify the mysql-ds.xml configuration file:

· Set <driver-class/> to com. mysql. jdbc. driver, <connection-url/> is set to jdbc: mysql: // localhost/<database>, where <database> is a MySQL database. The value of <database> can be set to test, which is the sample database in MySQL.

· Specify the jndi name of the data source in the JNDI-name element.

· Specify the username and password used to connect to the MySQL database. By default, the root user name does not require a password.

· Specify the type-mapping element as mySQL. The type-mapping element specifies the pre-defined Database type ing relationships in the standardjbosscmp-jdbc.xml deployment file. For MySQL databases, the type ing is mySQL.

The modified mysql-ds.xml is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?>
<Datasources>
<Local-tx-datasource>
<Jndi-name> MySqlDS </jndi-name>
<Connection-url> jdbc: mysql: // localhost/test </connection-url>
<Driver-class> com. mysql. jdbc. Driver </driver-class>
<User-name> root </user-name>
<Password> </password>
<Metadata>
<Type-mapping> mySQL </type-mapping>
</Metadata>
</Local-tx-datasource>
</Datasources>

We can obtain a JDBC connection from the data source by providing the data source JNDI Name:

InitialContext initialContext = new InitialContext ();
Javax. SQL. DataSource ds = (javax. SQL. DataSource)
InitialContext. lookup ("java:/MySqlDS ");
Java. SQL. Connection conn = ds. getConnection ();

  Configure logon information

Now we modify the login-config.xml configuration file based on the MySQL database settings. To log on to the MySQL database, the application policy MySqlDbRealm is necessary. Add the following <application-policy/> element to the login-config.xml:

<Application-policy name = "MySqlDbRealm">
<Authentication>
<Login-module code =
"Org. jboss. resource. security. ConfiguredIdentityLoginModule"
Flag = "required">
<Module-option name = "principal"> </module-option>
<Module-option name = "userName"> root </module-option>
<Module-option name = "password"> </module-option>
<Module-option name = "managedConnectionFactoryName">
Jboss. jca: service = LocalTxCM, name = MySqlDS
</Module-option>
</Login-module>
</Authentication>
</Application-policy>


By modifying the mysql-ds.xml and login-config.xml files, the JBoss 4.0 Server has been configured to use the MySQL database. In addition to the previous specific settings, you may also need to modify the JBoss deployment file and JBoss JDBC configuration file.

If the "create table" option is selected (by setting the create-table element in the jbosscmp-jdbc.xml to true), it is used to deploy the CMP Entity EJB and the primary key (or unique key) of the MySQL table) the length of the application exceeds 500 bytes, and an SQL syntax error is generated in the MySQL database during application deployment. For java. lang. for the CMP field of the String type, we can use it in the mySQL type ing of the standardjbosscmp-jdbc.xml deployment file for Java type java. lang. the SQL type of String is set to a lower VARCHAR value to reduce the length of the primary key (or unique key. Another possible problem is the column-name element in the jbosscmp-jdbc.xml deployment file. If the column name of a MySQL table is the same as that of a reserved MySQL table, an error occurs when the J2EE application is deployed in JBoss. To solve this problem, the column name is different from the reserved MySQL words.

   Convert WebLogic EJB applications

After the JBoss server for MySQL is created, you must convert the WebLogic EJB application to the JBoss EJB application, which involves modifying the deployment file. WebLogic entity EJB applications are deployed by EJB files (ejb-jar.xml, weblogic-ejb-jar.xml, and weblogic-cmp-rdbms-jar.xml), bean classes (CatalogBean. java), remote interface (Catalog. java) and home interfaces (CatalogHome. java. To deploy the entity EJB on the WebLogic server, you need to create an EJB. jar file. The structure of this EJB. jar file is as follows:

META-INF/
Ejb-jar.xml
Weblogic-ejb-jar.xml
Weblogic-cmp-rdbms-jar.xml
CatalogBean. class
Catalog. class
CatalogHome. class

The EJB structure information and application assembly information are specified in the deployment file. The structure information includes whether the EJB is a dialogue EJB or an entity EJB. Application assembly information in the ejb-jar.xml deployment file is specified in the assembly-descriptor element. This entity EJB deployment file in WebLogic includes ejb-jar.xml, weblogic-ejb-jar.xml, and weblogic-cmp-rdbms-jar.xml. The corresponding JBoss deployment files are ejb-jar.xml, jboss. xml, and jbosscmp-jdbc.xml. The conversion between these files is as follows.

The ejb-jar.xml deployment file is the same for WebLogic and JBoss, except for the multiplicity element. The multiplicity element in the ejb-jar.xml of the JBoss server needs to be capitalized, such as One or more, instead of one or more.

The ejb-jar.xml deployment file for the sample entity EJB is included in the sample code. The sample ejb-jar.xml defines an entity EJB called "Catalog. In this example, EJB has the CMP field catalogId, journal, and publisher. The primary key field is catalogId.

Convert weblogic-ejb-jar.xml to jboss. xml

Both the weblogic-ejb-jar.xml and jboss. xml deployment files are specific deployment files of the EJB vendor. To deploy the WebLogic EJB application to the JBoss application server, you must convert the weblogic-ejb-jar.xml deployment file to jboss. xml.

The root element in the weblogic-ejb-jar.xml is weblogic-ejb-jar. The root element in jboss. xml is jboss. In the jboss. xml and weblogic-ejb-jar.xml deployment files, the element that specifies the JNDI name of an EJB is either jndi-name or local-jndi-name. The weblogic-ejb-jar.xml deployment file for the sample entity EJB in this article is also included in the sample code. The DOCTYPE element of the weblogic-ejb-jar.xml deployment file is:

<! DOCTYPE weblogic-ejb-jar PUBLIC
"-// BEA Systems, Inc. // DTD WebLogic 8.1.0 EJB // EN"
Http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd>
The doctype of the jboss. xml deployment file is:
<! DOCTYPE jboss PUBLIC "-// JBoss // dtd jboss 4.0 // EN"
Http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd>

We use a custom XSLT style sheet jboss. xslt (included in the sample code) to convert the deployment file weblogic-ejb-jar.xml to jboss. xml. The style sheet creates jboss. xml, which is equivalent to the JBoss file of WebLogic's weblogic-ejb-jar.xml deployment file. The jboss. xml file generated using the jboss. xslt style sheet is also included in the sample code.

Convert weblogic-cmp-rdbms-jar.xml to jbosscmp-jdbc.xml

The weblogic-cmp-rdbms-jar.xml deployment file specifies the database continuity information for the CMP Entity EJB. The weblogic-cmp-rdbms-jar.xml file contains the table name of the entity EJB, the data that connects to the database, and the columns that correspond to the entity ejb cmp field. For example, the weblogic-cmp-rdbms-jar.xmldeployment file of ejbis included in the .zip file that can be downloaded. The JBoss deployment file that specifies CMP view EJB continuity information is a jbosscmp-jdbc.xml.

The root element of the weblogic-cmp-rdbms-jar.xml is weblogic-rdbms-jar; the root element of the jbosscmp-jdbc.xml is jbosscmp-jdbc. The data-source-name element that specifies the data source to connect to the database in the weblogic-cmp-rdbms-jar.xml file is equivalent to the datasource element feature in the jbosscmp-jdbc.xml deployment file. The weblogic-cmp-rdbms-jar.xml specifies that the field-map element of the ing relationship between the entity ejb cmp field and the columns in the database table is equivalent to the cmp-field element feature in the jbosscmp-jdbc.xml. The dbms-column element that specifies the column name in the weblogic-cmp-rdbms-jar.xml has the same functionality as the column-name element in the jbosscmp-jdbc.xml. The doctype of the weblogic-cmp-rdbms-jar.xml deployment file is:

<! DOCTYPE weblogic-rdbms-jar PUBLIC
'-// BEA Systems, Inc. // DTD WebLogic 8.1.0 ejb rdbms Persistence // en'
'Http: // www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd'>
Jbosscmp-jdbc.xml DOCTYPE is:
<! DOCTYPE jbosscmp-jdbc PUBLIC "-// JBoss // DTD JBOSSCMP-JDBC 4.0 // EN"
Http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd>


We use a custom XSLT style sheet jbosscmp-jdbc.xslt (included in the sample code) to convert the deployment file weblogic-cmp-rdbms-jar.xml to a jbosscmp-jdbc.xml. The style sheet establishes a jbosscmp-jdbc.xml, which is a JBoss file equivalent to WebLogic's weblogic-cmp-rdbms-jar.xml deployment file functionality. Jbosscmp-jdbc.xmlis also included in the. ZIP file.

The DTD of the WebLogic deployment file is different from that of the JBoss deployment file. When using custom XSLT, if there are some additional elements in the deployment file, you may need to make further modifications to convert the WebLogic deployment file to the JBoss deployment file. In the following section, we will deploy this EJB application on the JBoss server.

 Deploy the EJB application in JBoss

After you convert the WebLogic EJB deployment file to the JBoss deployment file, you must create a central EJB. jar file to deploy it on the JBoss server. The structure of the JBoss. jar file is as follows:

META-INF/
Ejb-jar.xml
Jboss. xml
Jbosscmp-jdbc.xml
CatalogBean. class
Catalog. class
CatalogHome. class

Compile the example EJB class and interface:

Java Catalog. java CatalogBean. java CatalogHome. java

Copy the JBoss deployment file ejb-jar.xml, jboss. xml, and jbosscmp-jdbc.xml to the META-INF directory. Use the jar tool to create a. jar file from the JBoss deployment file, class, and interface.

Jar cf CatalogEJB. jar CatalogBean. class
Catalog. class CatalogHome. class META-INF/*. xml

The JBoss entity EJB application is deployed. jar file (EntityEJB. jar) to the <JBoss> \ server \ default \ deploy directory (where <JBoss> is the directory installed by JBoss. When the server starts, the EJB application is deployed on the JBoss server. The deploy directory in the JBoss Application Server corresponds to the application (applications) directory in the WebLogic application server.

  Conclusion

You can migrate the entity EJB application deployed in WebLogic to the JBoss Application Server by converting the deployment file. Using similar steps, you can also migrate weblogic J2EE Web applications to JBoss by converting the WebLogic. xml deployment file to a jboss-web.xml.

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.