Javac ejb/Demo/demohome.java Javac ejb/Demo/demo.java Javac ejb/Demo/demobean.Java
(SessionDescriptor ; This file must start with SessionDescriptor or ; EntityDescriptor ; Indicate the name which the bean will be bound ; into the JNDI name as beanHomeName demo.DemoHome ; The enterprise Java Bean class (see step 4) enterpriseBeanClassName ejb.demo.DemoBean homeInterfaceClassName ejb.demo.DemoHome ; The home interface implemented by a class ; generated by the container provided tools ; see step 3 remoteInterfaceClassName ejb.demo.Demo ; See step 2 isReentrant false ; Always false for session beans stateManagementType STATELESS_SESSION ; Either STATELESS_SESSION or STATEFUL_SESSION. ; DemoBean is a stateless session bean sessionTimeout 5 ; seconds (controlDescriptors ; This section decides the run-time properties when ; a method is called. The DEFAULT sub-section applIEs ; to all methods, but can be overridden on a per-method ; basis, similar to the "AccessControlEntries" above. (DEFAULT isolationLevel TRANSACTION_SERIALIZABLE transactionAttribute TX_REQUIRED runAsMode CLIENT_IDENTITY ) ; end isolationLevel ) ; end controlDescriptors (environmentProperties maxBeansInFreePool 100 ) ; end environmentPropertIEs ) ; end SessionDescriptor
Name: ejb/demo/DemoBeanDD.ser Enterprise-Bean: True
jar cvfm Demo.jar ejb/demo/manifest.txt ejb/demo/*.class \ ejb/demo/*.ser 對 Demo.jar 的檢查應該產生類似於下面的輸出: jar tf Demo.jar META-INF/MANIFEST.MF Ejb/demo/Demo.class Ejb/demo/DemoBean.class Ejb/demo/DemoHome.class Ejb/demo/DemoBeanDD.ser
ejb/demo/DemoBeanEOImpl.class ejb/demo/DemoBeanHomeImpl.class ejb/demo/Skel5k5x705r2x671nd1i1vy2v524ua5y.class ejb/demo/Skel5q585f5sfzo601q4e725b233m5140.class ejb/demo/Stub5k5x705r2x671nd1i1vy2v524ua5y.class ejb/demo/Stub5q585f5sfzo601q4e725b233m5140.class
/export/weblogic/startTengah.sh #!/bin/sh # # Shell script to manually start Tengah # Server on UNIX systems CLASSPATH=$CLASSPATH:/export/weblogic/classes/Demo.jar echo $CLASSPATH Java -ms16m -mx16m -verbosegc weblogic.Server
cd /export/weblogic/classes jar xvf Demo.jar ejb/demo/DemoBeanDD.ser
包括新的企業JavaBeans 的裝載和啟動的有關說明。 /export/weblogic/weblogic.properties # # # # # # # # # # # # # # # # # # # # # # # # # # # Tengah Enterprise JavaBeans DEMO PROPERTIES # ------------------------------------------------- # Uncomment the appropriate lines below and modify # DBMS-related info and paths to match your particular # installation. # # Deploys the Enterprise JavaBean examples. Uncomment to use: weblogic.ejb.deploy=\ /export/weblogic/classes/beanManaged.jar,\ /export/weblogic/classes/containerManaged.jar,\ /export/weblogic/classes/statefulSession.jar,\ /export/weblogic/classes/ejb/demo/DemoBeanDD.ser # # weblogic.propertIEs file continues below... #
DemoClient.java (源代碼) /** * DemoClient -- demonstrates using a minimal * Java application to talk to the DemoBean * stateless session bean */ package ejb.demo; import javax.ejb.*; import javax.naming.*; import java.rmi.*; import java.util.Properties; import examples.ejb.statelessSession.interfaces.*; /** * DemoClient demonstrates using a minimal stateless session * bean. * Remember view session beans as an extension of your client * running in the server. */ public class demoClient { public static void main(String[] args) { System.out.println("\nBegin demoClient...\n"); parseArgs(args); try { // Create A DemoBean object, in the server // Note: the name of the class corresponds to the JNDI // property declared in the DeploymentDescriptor // From DeploymentDescriptor ... // beanHomeName demo.DemoHome Context ctx = getInitialContext(); DemoHome dhome = (DemoHome) ctx.lookup("demo.DemoHome"); // Now you have a reference to the DemoHome object factory // use it to ask the container to creat an instance of // the Demo bean System.out.println("Creating Demo\n"); Demo demo = dhome.create(); // Here is the call that executes the method on the // server side object System.out.println("The result is " + demo.demoSelect(); } catch (Exception e) { System.out.println(" = Error <="); e.printStackTrace(); } System.out.println("\nEnd demoClIEnt...\n"); } static void parseArgs(String args[]) { if ((args == null) || (args.length == 0)) return; for (int i = 0; i < args.length; i++) { if (args[i].equals("-url")) Integer.parseInt(args[++i]); else if (args[i].equals("-user")) user = args[++i]; else if (args[i].equals("-password")) password = args[++i]; } } static String user = null; static String passWord = null; static String url = "t3://localhost:7001"; /** * Gets an initial context. * * @return Context * @exception Java.lang.Exception if there is * an error in getting a Context */ static public Context getInitialContext() throws Exception { Properties p = new PropertIEs(); p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.T3InitialContextFactory"); p.put(Context.PROVIDER_URL, url); if (user != null) { System.out.println ("user: " + user); p.put(Context.SECURITY_PRINCIPAL, user); if (password == null) password = ""; p.put(Context.SECURITY_CREDENTIALS, passWord); } return new InitialContext(p); } }
Java ejb.Demo.democlIEntBegin DemoClient... Creating Demo The result is Hello World End DemoClIEnt...