Jbosside eclispe develops ejb2.1 instances

Source: Internet
Author: User

Jbosside eclispe development ejb2.1 instance (reprinted)

Ejb2.1 Development Instance 1. environment configuration 1) jdk1.5 file name: jdk-1_5_0_05-windows-i586-p.exe: https://jsecom16k.sun.com/ECom/EComActionServlet;jsessionid=31A76905496B86DCF9BCFE1CACE798952) compiler using JBoss eclipse ide1.5rc1 file name: JBossIDE-1.5RC1-Bundle-win32.zip download URL: http://www.jboss.com/products/jbosside/downloads3) Application Server: jboss4.0.3 (jboss4.0 version integration Tomcat) File Name: jboss-4.0.3-installer.jar download URL: http://www.jboss.com/products/jbossas/downloads4) install JDK -1_5_0_05-windows-i586-p.exe, unzip the downloaded jbosside-1.5rc1-bundle-win32.zip to a directory, this example D:/eclipse; double-click the jboss-4.0.3-installer.jar to install (Note: Do not. JAR file and WinRAR establish Association), this example installation directory D:/jboss-4.0.3. 5) set the environment variables, the environment variables in this example are as follows: java_home = C:/program files/Java/jdk1.5.0jboss _ home = D:/jboss-4.0.3Path = % java_home %/bin; % jboss_home %/bin; classpath = % java_home %/lib/DT. jar; % java_home %/lib/tools. jar; 6) Start JBoss, in the command line Input:> Cd D:/jboss-4.0.3/bin enter bin directory D:/jboss-4.0.3/bin> Run. bat press enter to run JBoss  
The JBoss startup screen is displayed. Enter http: // localhost: 8080 In the IE browser and press enter to view the JBoss welcome page. The environment is complete. 2. develop the EJB application 2.1 Development session bean1) Start eclipse2) create a j2ee1.4 project, file-> New-> Project click Next, enter the project name, in this example, fibonaci click Next, click Add folder in the source column, and enter SRC to store the source code and configuration files of the project. Click Finish. The directory structure is shown in Figure 3. Create a session bean and click SRC New-> other .. select Session Bean and click Next to enter the package name: fibonaci. EJB, file name: fibobean Click Finish to complete the Session Bean. The directory structure is as follows: add business logic method, click fibobean J2EE-> Add business method name: compute data type: Double [], the code for parameter int number [] Click Finish is as follows: public double [] compute (INT number) {If (number <0) {Throw new ejbexception ("argument shocould be positive");} double [] Suite = new double [number + 1]; suite [0] = 0; If (number = 0) {return suite;} suite [1] = 1; for (INT I = 2; I <= number; I ++) {suite [I] = suite [I-1] + suite [I-2];} return suite ;} 2.2 XDoclet setting EJB configuration (I think this one is interesting and it is a little different from lomboz + jbosside to develop EJB) 1) Right-click the EJB setting and choose Properties> XDoclet configurations> Add... Select ejbdoclet and add ejbdoclet. Set ejbdoclet attribute: a) destdir to src B. Add fileset for ejbspec to 2.1 and set attribute: a) dir to src B. Set des to **/* bean. java add deploymentdescriptor, attribute destdir add JBoss for src/META-INF, attribute: a) version is 4.0 B) destdir add packagesubstitution for src/META-INF, attribute a) package is ejb B) substitutewith adds homeinterface and remoteinterface for interfaces. You do not need to set properties and click OK. Right-click the project and choose run XDoclet to check that the console information runs successfully. interfaces and META-INF are created. So far, the EJB creation is complete. 2.3 create an HTTP servlet with the development servlet input package: maid. Web Name: computeservlet, select the init ()/service ()/dopost () method, and click Finish. See computeservlet. Java in the project and add the code Computeservlet. Java Code:Package maid. web; import javax. RMI. portableremoteobject; import javax. servlet. HTTP. httpservlet; import javax. servlet. servletexception; import javax. servlet. servletconfig; import Java. io. *; import Java. io. ioexception; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; import javax. naming. context; import javax. naming. initialcontext; import fig. interfaces. fibo; Import maid. interfaces. fibohome; public class computeservlet extends httpservlet {private fibohome home; Public computeservlet () {super ();} public void Init (servletconfig config) throws servletexception {try {context = new initialcontext (); Object ref = context. lookup ("Java:/COMP/ENV/EJB/fibo"); home = (fibohome) portableremoteobject. narrow (ref, fibohome. class);} catch (exception E) {Throw new servletexception ("lookup of Java:/COMP/ENV/failed") ;}} protected void dopost (httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception {resp. setcontenttype ("text/html"); printwriter out = resp. getwriter (); out. println ("<HTML> <! DoctypeHtml Public"-// W3C // dtd html 4.01 transitional // en" ><HTML> <? XML version = "1.0" encoding = "UTF-8"?><Application version = "1.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"> <display-Name> sum application </display-Name> <module> <EJB> fiboejb. jar </EJB> </module> <web-Uri> fiboweb. war </Web-Uri> <context-root>/fibo </context-root> </Web> </Module> </Application> 3.2 Create fiboejb. in jar, right-click the project and choose Properties> packaging deployments. In the Add directory, click project folder, and select the bin directory. Input: Fibonacci/EJB /*. class, maid/interfaces /*. class add file click project file, select ejb-jar.xmlPrefix input: META-INF the same way to add JBoss. xml3.3 create FiboEJB-client.jar add Folder:/maid/bin, includes: maid/interfaces /*. class3.4 create fiboweb. add Folder:/Fibonacci/bin to war, includes: Fibonacci/web /*. class Prefix: W EB-INF/classes add file:/Fibonacci/src/WEB-INF/web. XML, Prefix: WEB-INF add file:/Fibonacci/src/WEB-INF/jboss-web.xml, Prefix: WEB-INF add file:/Fibonacci/FiboEJB-client.jar (if not listed, you can enter it manually), Prefix: WEB-INF/lib add floder:/Fibonacci/docroot settings complete, as shown in: 3.5 create fiboapp. ear add file:/FIG/src/META-INF/application. XML, Prefix: META-INF add file:/Fibonacci/fiboejb. jar to add file:/FIG/fiboweb. the war is created, as shown in figure: 3.6 run pakaging right-click the project -> RUN pakaging. You can see the console information: Running succeeded. You can see the generated package file: fiboejb in the project. jar, FiboEJB-client.jar, fiboweb. war, fiboapp. ear, where fiboapp. ear is the JBoss deployment file. In 3.7, click "deploy application", right-click "Debug as"> "debug" and select "Application Server". In this example, jboss4.0.3 add resources and select "Source"> "add"> "Java project. Click debug to view the JBoss startup information on the console. After the startup is successful, click fiboapp. ear, right-click-> deployment-> deploy to. After the deployment is successful, you can see that the IE browser is successfully deployed. In the address bar, enter http: // localhost: 8080/fibo, you can see the page: click "compute". After the operation is successful, the page is displayed: Now, EJB development and deployment are complete. 4 deployment descriptor file 4.1 ejb-jar.xml <EJB-jar xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version = "2.1"> <description> fig </description> <display-Name> generated by XDoclet </display-Name> <enterprise-beans> <session> <description> Fibonacci EJB> </description> <display-Name> name for fibo </display-Name> <EJB-Name> fibo </EJB-Name> <? XML version = "1.0" encoding = "UTF-8"?> <! DoctypeJBoss Public"-// JBoss // DTD JBoss 4.0 // en" Http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd" ><JBoss> <enterprise-beans> <session> <EJB-Name> fibo </EJB-Name> <JNDI-Name> EJB/fibo </JNDI-Name> <method- attributes> </method-attributes> </session> </enterprise-beans> <assembly-Descriptor> </assembly-Descriptor> <resource-managers> </resource-managers> </JBoss> 4.3 web. XML <? XML version = "1.0" encoding = "UTF-8"?><Web-app xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version = "2.4"> <distributable/> <servlet> <description> servlet that compute fig suite </description> <display-Name> computation servlet </ display-Name> <servlet-Name> compute </servlet-Name> <servlet-class> Fibonacci. web. computeservlet </servlet-class> <init-param> <param-Name> a parameter </param-Name> <param-value> A value </param-value> </ init-param> </servlet> <servlet-mapping> <servlet-Name> compute </servlet-Name> <URL-pattern>/compute </url-pattern> </ servlet-mapping> <EJB-ref-Name> EJB/fibo </EJB-ref-Name> <EJB-ref-type> session </EJB-ref -type> <Home> Fibonacci. interfaces. fibohome </Home> <remote> Fibonacci. interfaces. fibo </remote> </EJB-ref> </Web-app> 4.4 jboss-web.xml <? XML version = "1.0" encoding = "UTF-8"?> <! DoctypeJBoss -Web Public"-// JBoss // DTD web application 2.4 // en" Http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd" ><JBoss-web> <EJB-ref-Name> EJB/fibo </EJB-ref-Name> <JNDI-Name> EJB/fibo </JNDI- name> </EJB-ref> </JBoss-web> 4.3 Application. XML <? XML version = "1.0" encoding = "UTF-8"?><Application version = "1.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"> <display-Name> sum application </display-Name> <module> <EJB> fiboejb. jar </EJB> </module> <web-Uri> fiboweb. war </Web-Uri> <context-root>/fibo </context-root> </Web> </Module> </Application> 5 References [1] JBossIDE-Tutorial-1.4.1.pdf [2] JBoss meets Eclipse: Introducing the JBoss-idehttp: // www.devx.com/opensource/article/20242/1954? PF = true [3] tutorial for building J2EE applications using JBoss and eclipsehttp: // www.tusc.com. au/tutorial/html/chap1.html [4] http://java.sun.com/xml/ns/j2ee/ [5] http://www.eclipse.org/[6] www.jboss.org

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.