A few steps below:
1 Establish a test web module
2 Establish an IDEA EJB module to write EJB
3 compile, package
4 write test page
5 Release EJB, Web Test Module, Test EJB
1 Create a web test module.
In the default user_projects / domains / mydomain / applications directory, create a folder called web. This folder is our Web module we test EJB.
Create a new Web-INF folder under the web folder, create a new LIB folder under Web-INF.
New web.xml files under Web-INF, as follows:
XML Version = "1.0" encoding = "UTF-8"?>
web-app>
OK. The web test module is completed.
2 Establish an IDEA EJB module to write EJB
Open IDEA, select File-New-EJB Modules, change the module name to "EJBSAMPLES", as shown below:
In the server option, select WebLogic, and the rest is set by default. Finally finish.
New package under the SRC folder. The name is as follows: com.diegoyun.ejb.slb, as shown below:
Put your mouse on the module name, right, select: New-sessionBean. Then set the following attribute box in the pop-up:
Package: Select / Enter com.diegoyun.ejb.slb
The remaining information IDEA will help you automatically set, the entire property box property is as follows:
Click OK to end
At this time, the attribute configuration interface of the EJB will pop, as follows:
In Display Name, enter HelloWorldejb
Then switch to the WebLogic Server page, enter JNDI NAME as follows: EJB / Session / HelloWorldejb
The interface is as follows:
Close this property page. Idea has helped you write the configuration information of EJB. You can open the EJB-JAR.XML and WebLogic-EJB-JAR.XML of META-INF /.
At this time, there should be three files under com.diegoyun.ejb.slb: HelloWorld, HelloWorldbean and HelloWorldHome
Add a method to the HelloWorld interface as follows:
Public interface helloworld extends ejbobject {
Public String getGreeting (String Name) throws RemoteException;
}
Add a method to the HelloWorldBean interface as follows:
Public class helloworldbean imports sessionbean {
...............
// omit ivit
Public string getGreeting (string name) {
Return "Hello," Name;
}
}
OK. Your HelloWord EJB is already written.
3 Compile, package, release EJB this example uses a web way to access EJB. And did not pack the Web module and EJB JAR into EAR. So I must first compile the EJB source to JAR, release this JAR, then copy it to the lib directory of the test web module so that the web page can access bean.
This example uses ANT scripts to perform commands such as compilation and packaging. Create a build.xml script under the Idea's EJBSAMPLES module, as follows:
target>
Destdir = "$ {build}" incrudes = "** / *. java" /> target> target> target> provject> To install the installation of your machine WebLogic, modify the following information: At this point, the preparation of EJB is completed. Run the script just now. Ant build.xml Then check if there is an EJB jar under the web test module / web-inf / lib, whether there is an EJB JAR in the weblogic UPLOAD directory. If not, please check your configuration in the following steps. 4 write test page for testing In the web module, create a new Hello.jsp, the content is as follows: <% @ page language = "java"%> <% @ page import = "com.diegoyun.ejb.slb.helloWorld, com.diegoyun.ejb.slb.helloworldhome, Javax.ejb. *, Java.math. *, Javax.naming. *, Javax.rmi.PortableRemoteObject, Java.rmi.RemoteException "%>
hEAD>