Develop J2EE apps using Eclipse
Introduction:
I. Download, Install and Configure II. Using Eclipse Development Web Application III, use Eclipse to develop EJB four, summarize the reference information About the author Appendix: jboss320.server
Jiang Wei (jiangww@lenovo.com) Development Engineer of Lenovo Group Software Design Center June 2003
Eclipse is a very good integrated development environment. This open original code project under IBM has been familiar with the majority of Java developers after a period of IBM. The emergence of Eclipse provides Java developers with free use of powerful Java IDE opportunities, through the integrated plugin, Eclipse's functionality can be expanded to support a variety of applications.
Lomboz is a free Eclipse Plugin that integrates many Java application servers, J2EE components, and web applications to Eclipse, which can help Java developers build, test, and deploy J2EE applications.
JBoss is an open original code, a powerful Java application server, is also a Java application server that is currently the favorite of Java developers, and is rated as an editor of Java World as an optimal application server in 2002. The downloaded quantity so far in 2003 has exceeded 15 million times.
First, download, installation, and configuration
1. Eclipse download and installation
First you need to install JDK, you can download the latest version and install it up to Sun's website.
Then go to http://www.eclipse.org/ to download the latest version of Eclipse, the current latest version is 2.1. After downloading, decompress it into the directory you want, for example, D: / Eclipse, execute Eclipse.exe directly, automatically look for JDK and complete the relevant settings when executed, and then enter the main interface of Eclipse. About Eclipse's basic usage, developerWorks, Eclipse's website, and Eclipse's instructions are described in detail, which is not described in detail.
2. JBoss download, installation
The latest version of JBoss is 3.2.1, but I think this version has some problems. There will be some JAR kits when starting the server, resulting in WARN and Error. So I recommend download 3.0.7, or you can download the JBoss version 3.0.7 of Tomcat 4.1.24.
After downloading, decompress, we assume jboss_home for the primary directory of JBoss, execute jboss_home / bin / run.bat, start the JBoss server. Generally, it will be started for about 1 minute.
3. Lomboz download, installation, and configuration
The latest version of Lomboz is 2.1, we assume that the primary directory of Eclipse is Eclipse_home, download it into the eclipse_home / plugins directory, so there is more than one called com.ObjectLearn.jdt.j2ee directory.
The Eclipse is then started, and the Customize Perspective is automatically displayed. If you do not appear, you can also display this dialogue through the function table "Window-> Customize Perspective", as shown below:
Expand File-> New, select all options related to Lomboz;
Expand Window-> Show View, choose Lomboz J2EE View;
Expand Other and select Lomboz Actions.
Confirm OK.
Below you want to configure Lomboz:
First, open the property dialog box to ensure the settings in Java-> New Project:
Then, in the Lomboz property, make sure the following settings:
Finally, the server attribute is set.
Lomboz pre-defines some commonly used Java server configuration, which is placed under the Eclipse_home / plugins / com.objectlearn.jdt.j2ee / servers directory, you can use the text editor to modify (unless you use the server is not In the server identified by Lomboz, otherwise I don't recommend you), or you can set it in the Eclipse's properties dialog box, the process is very simple, as shown below:
Remember to select Apply after each modification.
The above figure is the configuration under the Properties tag. The ClassPath label does not need to be changed under the label (note: If you do not adopt the advice started by the article, the version of JBoss3.2.0 is used, which may need to manually add multiple JAR suits, there will be some Trouble. I don't know if this is a JBoss problem, and I will explain it below.
Through the above three steps, Lomboz has completed the support and JBoss configuration of J2EE development. You can enter the second part of the article "Using Eclipse Development Web Application".
Precautions:
a. If the server is not in the approved server:
Create an archive of a subscriber name Server in the eclipse_homend.jdt.j2ee / servers directory, and then edit the Server file with the text editor according to the existing Server file as the model. After establishing a new Server file, you can perform related settings in the property page of Lomboz.
b. If you use the JBoss 3.2.0 version.
Open Window> Preferences> Lomboz> ServerDefinitions, select your server, then select the ClassPath tab, add the following JAR suite to Server Library:
JBoss_Home / lib / concurrent.jar
JBoss_Home /Lib/boss-system.jar
JBoss_Home / Server/default/lib/jboss.jar
JBoss_Home / Server/default/lib/jpl-pattern.jar
JBoss_Home / Server/default/lib/jpl-util.jar
JBoss_Home / Server/default/lib/jnpserver.jar
JBoss_Home / Server/default/lib/jboss-transaction.jar
The entire contents of my JBoss320.server file are presented in the last part of this article.
Second, use Eclipse development web applications
First, open File-> New-> Lomboz J2EE Project, build a J2EE Project called TestJ2ee.
Click Next, use the preset value, click Next, enter the next dialog box, add the already configured server in the TargeTed Server, as shown below:
In Web Modules and EJB Modules, create a new web module and EJB module, in this example, we named myWeb and MyEJB, then click Finish. In this way, a framework of a J2EE project is automatically generated. Under myWeb modules, two JSP files are automatically generated: index.jsp and error.jsp, and the setting file below the web-INF file. We can add your own JSP file and servlet on this basis, and then build a project.
Point the button of the Lomboz J2EE Project Outliner on the tool column of Eclipse:
In this way, Lomboz J2EE VIEW appears on Eclipse, as shown below:
Since I have already deployed another web server: Tomcat, the two servo it binds in the MYWEB module, and the red tag next to JBoss 3.0 all indicates a preset server. You can select the WEB module to select the WEB module to select the preset server, as shown below:
After selecting the server, press the right-click selection server in Lomboz J2EE VIEW, select the execution server, wait for the server to start, press the right click to select the Web module, select Deploy Module, so that the web module is completed Deployment on the server. Open the IE browser, enter http://127.0.0.1:8080/Myweb, you can see the web application you develop.
Here, there is a point here. If you use Tomcat as a web server, you need to restart the Tomcat server when the web module needs to be redeployed. JBoss does not need to do this.
Precautions:
If you start the JBoss server in Eclipse, this problem is encountered:
Error Occurred During Initialization Of VM
Java / Lang / NoclassDeffounderror: Java / Lang / Object
Generally encountered this problem, it may be because JRE is not set, please expand Java-> Installed Jres in the preference dialog in Eclipse, check if JRE is set; then open the project's project property dialogue, see Java Is there a JRE SYSTEM LIBRARY in the Build Path, no words, click Add Library, add JRE SYSTEM LIBRARY.
Third, use Eclipse to develop EJB
In the second part "use Eclipse Development Web Application", we have added an EJB module called MyEJB in the J2EE project in TestJ2ee. Here we add a session bean to the MyEJB module through the Lomboz EJB Creation Wizard.
Click File-> New-> Lomboz EJB CREATION WIZARD, or press the right button on the MyEJB module, select New-> Lomboz EJB CREATION WIZARD, show the following dialogue:
Create a Stateless Session bean called Myejb under com.dino.testj2ee.myejb. After completing, in the SRC directory of the TestJ2ee project, a file named myejbbean.java appears. Press Right-click on this file file to select New-> Lomboz EJB Method Wizard, you can add various methods to this EJB. I added a HelloWorld method and returned a string type. As shown in the figure below: Then, you need to add myejb this session bean to the Myejb module: Press Right click on MyEJB.java, select Lomboz J2EE ... -> Add EJB To Module, select MyEJB, OK.
Point right click on the MyEJB module, select Lombozj2ee ... -> Generate EJB CLASSES, which automatically produces the following files below the EJBSRC directory:
Myejbhome.java
Myejbrome.java
Myejblocalhome.java
Myejblocal.java
Myejbsession.java (MyEJBSESSION EXTENDS MyEJBBEAN)
MyEJBUTIL.JAVA
After Build Project, the module is automatically packaged. Then you can deploy the EJB module according to the steps to deploy the Web module.
Finally, we build an app to test EJB.
Open a dialogue through the file-> new-> Lomboz EJB Test Client Wizard, press the picture to fill in:
After completion, TestMyejb.java produced under the src directory, adding a test code in the TestBean method:
System.out.println (MyBean.helloworld ());
If the JBoss server has already started, and the MYEJB module has deployed, the testmyejb is executed, and it will be displayed on the Console window:
HEHE, I can Deploy EJB by Eclipse!
Fourth, summary
Through the above introduction, we learned that Lomboz developed J2EE applications very simple, and Eclipse, Lomboz and JBoss tools are free open original code project, so such a combination is more attractive to Java developers. .
For developing complex J2EE applications, the above introduction may not be comprehensive enough, I hope everyone will experience the process of doing the project, and then put the experience in developerWorks to share.
Reference:
Www.eclipse.org Eclipse's official website. Www.jboss.org Jboss's official website. Www.objectLearn.com Lomboz website, About Lomboz teaching documents. Eclipse In Action: a guide for Web Developers, by David Gallardo, Ed Burnette and Robert McGOvern, Manning Publications. A good book developed using Eclipse. JBoss 3.0: Quick Start Guide, by jboss group. A good book about JBOSS.
About author
Jiang Yan, is the development engineer of Lenovo Group Software Design Center, passionate about J2EE and Web Services technology. In leisure, I like to read computer books and have frequently browsed each Java forum; on the evening of the weekend, I will generally watch the live broadcast of the voluntary football match in front of the TV. Address: Pioneer Building, No. 7 Kondow Road, Outdoor Information Industry Base, Beijing, China Post Code: 100085. You can get in touch with him through E-mail: jiangww@lenovo.com. Appendix: jboss320.server
EjBModules = "true" WebModules = "true" Earmodules = "true"> TYPE = "Directory" default = "d: /jboss-3.2.0" /> TYPE = "string" default = "127.0.0.1" /> TYPE = "string" default = "8080" /> TYPE = "string" default = "jboss32" /> TYPE = "Directory" default = "d: /jboss-3.2.0" /> serverclasspath> clientclasspath> serverdefinition>