Migrate WebLogic EJB program to JBoss

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

WebLogic Server is a top-level commercial applicationProgramServer. But for small-scale developersSource codeThe 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 MySQL Open SourceCodeDatabase 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 = 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.

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.