Migrate Weblogic EJB program to JBoss

WebLogic Server is a top-level business application server. However, for small-scale developers, JBoss, a standard based application server that develops source code, can be used to replace commercial application servers such as Weblogic or WebSphere. Unfortunately, applications developed in Weblogic cannot be deployed in JBoss. JBoss migration service provides us with support for migrating applications to JBoss. Instead, it is possible to migrate applications to JBoss by migrating vendor specific deployment file information to JBoss. To demonstrate how to migrate applications to JBoss, we will migrate an EJB application with Oracle database developed in Weblogic to JBoss application server with MySQL database. In order to configure the JDBC connection of MySQL database, the pre installed software needs to download the MySQL database driver class. 1. Download MySQL jdbc driver Jar file 2. Download and install MySQL database server 3. Download and install JBoss 4.0 application server to develop a Java application. We will use it and XSLT to convert Weblogic deployment file into JBoss deployment file. The deployment file can also be transformed using XSLT tools. Overview applications developed in Weblogic cannot be deployed in JBoss without modification. The deployment file of JBoss application is different from that of Weblogic. In this paper, We will migrate an entity EJB application example developed in Weblogic to JBoss. The migration method is to convert the Weblogic deployment file into a JBoss deployment file. The sample application includes a catalog entity EJB. The bean class (catalogbean. Java), remote interface (catalog. Java), and home interface of the EJB (cataloghome. Java) are all in the weblogic-jboss-resources.zip sample file downloaded in this article. We will use the MySQL open source database to configure JBoss applications. Deploying Weblogic EJB applications into JBoss does not need to modify the entity EJB class, but only the deployment file of the EJB. Configuring JBoss and MySQL MySQL is an open source Database, which is suitable for open source projects and small organizations. In order to configure JBoss and MySQL databases, the following modifications need to be made. Configure the JBoss classpath. In order to use JBoss 4.0 and MYSQL, we first need to add the driver class The. Jar file (mysql-connector-java-3.0.9-stable-bin. Jar) is copied to the JBoss / server / default / lib directory. JBoss is the directory where the JBoss application server is installed. The. Jar and. Zip files of the Lib directory are contained in the classpath of the JBoss server (classpath). Configure the MySQL data source. In order to use the MySQL data source, you need to copy < JBoss > / docs / examples / JCA / mysql-ds.xml to < JBoss > / server / default / deploy directory. When the JBoss server starts, the data source configuration file in the deploy directory will be deployed. Modify the mysql-ds.xml configuration file according to the following steps: ・ Set < driver class / > to com MysqL. jdbc. Driver, < connection URL / > is set to JDBC: MySQL: / / localhost / < Database >, where < Database > is the 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 user name and password 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 standardjbosscmp JDBC The predefined database type mapping relationship in the XML deployment file. For a MySQL database, the type mapping is mysql. Modified MySQL DS XML is as follows: < 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 JNDI name of the data source: in itialContext initialContext = new InitialContext();   javax. sql. DataSource ds = (javax.sql.DataSource)   initialContext. lookup("java:/MysqLDS");   java. sql. Connection conn = ds. getConnection(); Configure the login information. Now let's modify login - config according to the MySQL database settings XML configuration file. In order to log in to the MySQL database, the application policy mysqldbrealm is necessary. Give login config XML add the following < application policy / > element: < application policy name = "mysqldbrealm" > < authentication > < login module code = "org. JBoss. Resource. Security. Configuredinidentityloginmodule" 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 > Modify MySQL DS XML and login config XML file, JBoss 4.0 server has been configured and can use MySQL database. In addition to the previous specific settings, you may need to make some changes to the JBoss deployment file and JBoss JDBC configuration file. If the "create table" option is selected (by setting the create table element in jbosscmp-jdbc.xml to true) to deploy the CMP entity EJB, and the primary key of the MySQL table If the length of (or unique key) exceeds 500 bytes, an SQL syntax error will be generated in the MySQL database during application deployment. For the CMP field of java.lang.string type, we can reduce the primary key by setting the SQL type for java.lang.string to a lower varchar value in the MySQL type mapping of standardjbosscmp-jdbc.xml deployment file (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 the MySQL reserved word, an error will be generated when deploying J2EE applications in JBoss. The solution to this problem is to make the column name different from the MySQL reserved word.

After establishing a JBoss server using mysql, you must now convert the Weblogic EJB application into a JBoss EJB application, which involves the modification of the deployment file. Weblogic entity EJB application consists of EJB deployment files (ejb-jar.xml, weblogic-ejb-jar.xml and weblogic-cmp-rdbms-jar.xml), bean class (catalogbean. Java), remote interface (catalog. Java) and home interface (cataloghome. Java). In order to deploy entity EJBs 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 EJB structure information and application Program assembly information is specified in the deployment file. The structure information includes a description of whether the EJB is a dialog EJB or an entity EJB. ejb-jar. The application assembly information in the XML deployment file is specified in the assembly descriptor element. The EJB deployment file of this entity in Weblogic includes EJB jar xml、weblogic-ejb-jar. XML and Weblogic CMP RDBMS jar xml。 The corresponding JBoss deployment file is EJB jar xml、jboss. XML and jbosscmp JDBC xml。 The conversion between these files is shown below.   ejb-jar. The XML deployment file is the same for Weblogic and JBoss, except for the multiplicity element. EJB jar.jar of JBoss server The multiplicity element in XML needs to be capitalized, such as one or many, not one or many. EJB jar. EJB for example entity EJB The XML deployment file is included in the sample code. Example EJB jar XML defines an entity EJB called "catalog". This sample EJB has CMP fields catalogid, journal, and publisher. Its primary key field is catalogid. Put Weblogic EJB jar XML to JBoss. XML xml   weblogic-ejb-jar. XML and JBoss XML deployment files are EJB vendor specific deployment files. In order to deploy Weblogic EJB application to JBoss application server, Weblogic EJB jar The XML deployment file is converted to JBoss. XML xml。   weblogic-ejb-jar. The root element in XML is Weblogic EJB jar. jboss. The root element in XML is JBoss. In JBoss XML and Weblogic EJB jar The element in the XML deployment file that specifies the JNDI name of an EJB is JNDI name or local JNDI name. The example entity EJB in this article is Weblogic EJB jar The XML deployment file is also included in the sample code. weblogic-ejb-jar. The DOCTYPE element of the XML deployment file is: the DOCTYPE of jboss.xml deployment file is: we use a custom XSLT stylesheet jboss.xslt (included in the sample code) convert the deployment file weblogic-ejb-jar.xml to jboss.xml. This stylesheet establishes jboss.xml, which is a JBoss file equivalent to Weblogic's weblogic-ejb-jar.xml deployment file. The jboss.xml file generated by using the jboss.xslt stylesheet is also included in the sample code. Convert weblogic-cmp-rdbms-jar.xml to jbosscmp-jdbc.xml c-cmp-rdbms-jar. The XML deployment file specifies the database persistence information of the CMP entity EJB. weblogic-cmp-rdbms-jar. The XML file contains the table name of the entity EJB, the data source connected to the database, and the column corresponding to the entity EJB CMP field. Weblogic - CMP - RDBMS - jar. For example entity EJB The XML deployment file is included in the downloadable Zip file. The JBoss deployment file that specifies the CMP view EJB persistence information is jbosscmp JDBC xml。   weblogic-cmp-rdbms-jar. The root element of XML is Weblogic RDBMS jar; jbosscmp-jdbc. The root element of XML is JBoss CMP JDBC. weblogic-cmp-rdbms-jar. The data source name element of the data source specified in the XML file to connect to the database is the same as jbosscmp JDBC The datasource element in the XML deployment file is quite functional. weblogic-cmp-rdbms-jar. XML specifies the field map element and jbosscmp JDBC. XML of the mapping relationship between the entity EJB CMP field and the column of the database table The CMP field element in XML is quite functional. weblogic-cmp-rdbms-jar. The DBMS column element that specifies the column name in the XML is the same as jbosscmp JDBC The column name element in XML is quite functional. weblogic-cmp-rdbms-jar. The DOCTYPE of the XML deployment file is: we use the custom XSLT stylesheet jbosscmp-jdbc.xslt (included in the sample code) convert the deployment file weblogic-cmp-rdbms-jar.xml to jbosscmp-jdbc.xml. This stylesheet establishes jbosscmp-jdbc.xml, which is a JBoss file equivalent to Weblogic's weblogic-cmp-rdbms-jar.xml deployment file. Jbosscmp-jdbc.xml is also included and downloaded in the. Zip file. The DTD of Weblogic deployment file is different from that of JBoss deployment file. Use When customizing XSLT, if there are some additional elements in the deployment file, it may need to be further modified. You can convert the Weblogic deployment file into a JBoss deployment file. In the following section, we will deploy the EJB application on the JBoss server. After deploying the EJB application in JBoss and converting the Weblogic EJB deployment file into JBoss deployment file, you must create a heart EJB Jar file to deploy to the JBoss server. The JBoss The structure of the jar file is as follows: meta inf / EJB jar xml   jboss. xml   jbosscmp-jdbc. xml   CatalogBean. class   Catalog. class   CatalogHome. Class compilation example EJB class and interface: Java catalog java CatalogBean. java CatalogHome. The JBoss deployment file EJB jar. Java xml、jboss. XML and jbosscmp JDBC Copy the XML to the meta inf directory. Use the jar tool to build a database from JBoss deployment files, classes, and interfaces Jar file.   jar cf CatalogEJB. jar CatalogBean. class   Catalog. class CatalogHome. class Meta-INF/*. XML to deploy the JBoss entity EJB application is to The EJB. Jar file (entityejb. Jar) is copied to the < JBoss > \ server \ default \ deploy directory (where < JBoss > is the directory where JBoss is installed). When the server starts, the EJB application is deployed on the JBoss server. The deployment directory in the JBoss application server is the same as the application in the Weblogic application server (Applications) directory correspondence. Conclusion the entity EJB application deployed in Weblogic can be migrated to JBoss application server by converting the deployment file. Using similar steps, Weblogic J2EE Web application can also be migrated to JBoss by converting weblogic.xml deployment file to jboss-web.xml.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>