Based on JBoss J2EE application development Author: Luo Shifei
(E_mail: j2eebeans@yahoo.com.cn)
(All copyright owners, the reference specified, do not use commercial purposes, Written on August 19, 2003)
Keywords: JBoss 3.2.1 J2EE JNDI DATABASE
JBoss, as a J2EE application server, with its EJB container's excellent performance, technology trend, and development deployment J2EE application's convenience of J2EE developers' trust. Among them, several features such as JMX architecture, hot deployment (Hot deploy), rapid development EJB applications are like other commercial servers. Although it does not have a major defect, after all, it is the development mode of Open Source, there is very little document, so it is very good to master, and the development of JBoss-based applications is still not from the heart. This article combines its own development experience, gives some relevant precautions and rules for J2EE under JBoss 3.2.1. Among them, readers must know JBoss 3.2.1 as a transition product of JBoss (compared to JBoss 3.0.x, JBoss 4.x), natural things and JBoss 3.0.x, JBoss 4.x have a big difference. However, in general, the content introduced herein is generally suitable for JBoss versions. After downloading JBoss 3.2.1, you can run JBoss without a space-free directory path, so it is convenient, provided that the target machine has installed Java 2 Standard Edition. Start our journey after everything is ready. (Suppose JBoss 3.2.1 is installed in: c: /jboss-3.2.1_tomcat-4.1.24, this use default configuration) 1. The settings of the relevant profile are developed to develop J2EE applications, and the operation database is an essential content; adjustment The details of the log output become the key to the debugging J2EE application; the Templary process for EJB is the core of the J2EE application. Wait, these contents are what we need to know.
(1) Configuration of data source:
In JBoss 3.2.1, the steps to configure the data source are simple, JBoss 3.2.1 itself has a configuration instance of the mainstream database, under the directory: c: /jboss-3.2.1_tomcat-4.1.24/docs/examples/jca . Specific use of that profile depends on the database of the target user. If you are SQL Server 2000, you need to use the MSSQL-DS.XML file (support local transaction) or MSSQL-XA-DS.XML file (support global transaction); if it is an Oracle 9i database, you need to use Oracle-DS.xml files. Or Oracle-Xa-DS.xml file. and many more. Here is as an example of SQL Server 2000. First copy the MSSQL-DS.XML file to the directory: c: /jboss-3.2.1_tomcat-4.1.24/Server/default/deploy under. Then open the file and make the following modification:
(2) Detail of the log of the log: Since JBoss 3.2.1 is developed using log4j management its log information (strictly speaking, it expands log4j), so understands the log4j mechanism to help understand JBoss 3.2.1 management logs. The way. JBoss 3.2.1 uses a JMX architecture, and with the .xml file type as a configuration file, you can find the log4j.xml file in the directory: c: /jboss-3.2.1_tomcat-4.1.24/server/default/conf . For example, one of the configuration examples are as follows:
After completing the above two steps, the reader can see the JDBC call details emitted by Entity Beans when debuging Entity Beans.
(3) The configuration of the TOMCAT container related parameters:
If the target reader uses JBoss 3.2.1 integrated version of Tomcat 4.1.24, you can be located in the directory by adjustment: c: /jboss-3.2.1_tomcat-4.1.24/server/default/deploy/jbossweb-tomcat.sar Web.xml and directory: c: /jboss-3.2.1_tomcat-4.1.24/server/default/deploy/jbossweb-tomcat.xml files under the JBoss-Service.xml files under the target reader to achieve specific needs. For example, if you want to change the HTTP service port to 80, you can modify the jboss-service.xml file; if you want to process more file types to process the target J2EE application, you can modify the web.xml file. (4) The placement of the relevant class library:
If your application involves a third-party library, such as JDBC Driver, you can store these JDBC Driver to directory: c: /jboss-3.2.1_tomcat-4.1.24/server/default/lib. Note, not a directory: c: /jboss-3.2.1_tomcat-4.1.24/lib. If it is related to the target J2EE application, it can be stored in the target .war (or. Pear), or under the XXX.WAR directory. No matter what situation, you need to follow J2EE specifications.
Of course, JBoss 3.2.1 has a lot of configuration files, such as mail-service.xml files that provide email services, and so on. Here is just some of the information, if you have related questions, you can try some content introduced in this article to solve your problem. Thank you.
Second, developing EJB applications If developing EJB applications, it is recommended to use JBoss as a development server because development, debugging, deployment speed is fast. If other commercial servers are used, their compilation is very slow due to different mechanisms. If you use Entity Beans technology, you need to know how to do this. First, how many operation portions have the data source of your target system, that is, whether the database is presented outside the Entity Beans. If so, you need to adjust the
to be continued. . . . . .
Connect. . . . . .
Among them, this paper focuses on the discussion of EJB transaction processing. In general, J2EE application servers support JDBC transactions, JTA transactions, and container management transactions. At the same time, it is best not to use the above three transaction types in the program, such as nested JDBC transactions in JTA transactions; . For example, the following will give a rollback JDBC transaction code example: public void processt (string order) {context initctX = new initialContext (); javax.sql.datasource ds = javax.sql.datasource Initctx.lookup ("Java: Comp / env / jdbc / ordersdb "); java.sql.connection conn = ds.getConnection (); try {conn.setAutOCommit (false); // Change the default submission method of JDBC transactions OrderNo = CreateORDER (ORDERS); UpdateOrDerstatus ORDERNO, "ORDERS CREATED"); Conn.commit (); // Submit JDBC Transaction} Catch (Exception E) {Try {TRY {Conn.Rollback (); // Roll Roll SJDBC Transaction Throw new EJBEXCEPTION ("Transaction rollback:" E.GetMessage ());} catch (SQLEXCEPTION SQLE) {throw new ejbexception ("SQL operation error:" SQLE.GetMessage ());}}} (Modify Self). Transactions in J2EE (RedBooks) .pdf A bean management JDBC transaction)
The following is a JTA transaction code example:
public void processOrder (String orderMessage) {UserTransaction transaction = mySessionContext.getUserTransaction (); // get JTA transaction try {transaction.begin (); // start JTA transaction orderNo = sendOrder (orderMessage); updateOrderStatus (orderNo, "order sent" ); transaction.commit (); // Submit JTA transaction} catch (Exception E) {TRY {transaction.rollback (); // Rollback JTA transaction} catch (systemException se) {se.printstacktrace ();} throw new EJBEXCEPTION ("Transaction rollback:" E.GetMessage ());}} (Modify Self, Transactions in J2EE (RedBooks).
At the same time, if the session bean uses JTA management transactions, you must do not get JTA transactions through JNDI, otherwise the result is unimaginable; but use similar, "MySessionContext.getusertractions) method is obtained. Finally, the container management transaction (CMT) can be used. In the use of the CMT, if the declaration allows the container to complete the transaction rollback, the target EJB application must throw the system-level exception, otherwise the container does not meet the ACID of the transaction. In the anomalous class of the package javax.ejb, other exceptions are all application-level exceptions in addition to NosuCheXception and EJBEXCeption belongs to the system-level exception. The above 3 points is worth reading. Some readers may always encounter their own ACID that has already been declared as "required" in using the EJB CMT, but it is not possible to guarantee the ACID. Therefore, it is hoped that the reader pays attention to the different ways of transaction use in J2EE applications. For details, you can refer to the transaction section of J2EE Tutorial book. In addition, 1) In the development of the Entity Beans, it is possible to use the CMP to do not use the BMP. If the BMP is intended, it is better to use Session Bean JDBC, where you can control your transaction through JTA (if the performance problem is not very important). 2) If the transaction (ie, through the declaration), it is possible to improve the development efficiency, making you more focused on the business logic itself. 3) Try to use the techniques adopted by J2EE specifications. If the target system needs to be transplanted, many technologies unique to JBoss are used, and their transplantation is very troublesome. Third, in the case of developing Web applications, developing web applications is best to use some THIRTY-Part software or Framework. For example, struts, log4j, webmethods, etc. Its advantage is obvious. For now, Struts' application is basically the standard for developing web applications. The upcoming JSF is very good to achieve complement and integration with Struts. At the same time, JSF will also bring revolution to the rapid development of JSP web front-end applications. In addition, Struts also promoted the development of JSF. The process of developing a web application under JBoss 3.2.1 is similar to other application servers. At the same time, JBuilder 8, 9 has supported Struts 1.1. If the reader needs JBoss 3.2.1, combined with the article, EJB, JSP, Servlet, JavaBean-related instances, you can give me some suggestions.
4. Summary through these two articles, a few basic issues related to the development J2EE application have been preliminary. The problem involved in developing J2EE applications is a system engineering issue, nor a few articles, and several books can answer clearly. Many content need everyone to explore, learn, and progress in practice. thank you all. Welcome everyone to give me a letter, discuss J2EE related development, application issues.