This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This is a step by step guide on how to deploy the Advice beans to Weblogic Server 8.1 as John Liang suggested in a previous topic. I will start from the beginning and try to explain every required step. I will only use the build tool Ant and the Weblogic command line tool weblogic.appc to make the process as transparant as possible. I made this example on Windows 2000, but it works the same way on Linux (The only differences are how you Start the server and configuration wizard and the bea.home parameter in the build.properties file). If you have the Weblogic server up and running and have configured a domain already, you can skip down to point 4. 1. Download Bea Weblogic Server 8.1 from http://commerce.bea.com/index.jsp. 2. Install Weblogic. The installation process is very easy. a) I'm choosing C:\bea as my BEA Home Directory. b) I'm choosing to make a complete installation. c) I'm keeping the default values for everything. More information about the installation process is availible here: http://edocs.bea.com/wls/docs81/install/index.html
3. Create a new domain for the application. a) Go to Start/Program/Bea WebLogic Platform 8.1/Configuration Wizard. b) Select Basic WebLogic Server Domain as Configuration Template. c) Choose Express Configuration. d) I'm choosing weblogic as password. e) Choose developing mode and select the Sun SDK that is supplied by Bea. f) Let mydomain be the name of the configuration. More information on how this is done is availible here: http://edocs.bea.com/wls/docs81/adminguide/createdomain.html#1127576 4. I will use the same file structure att Kathy uses in Head First EJB. I start with only the source-files in the src folder.
You can download the stucture including all files from http://www.offthebeatentrack.se/advice/advice.zip 5. I will be using the ant-tool to compile the source-files and to create the stubs and container generated implementations of the interfaces (EJBObject and EJBHome). Ant can be downloaded from: http://ant.apache.org. Ant uses a build.xml file to compile files and for other stuff. The build.xml file and all other files I use in this example is included in advice.zip. 6. To be able to compile the source-files I put the build.xml file and the build.properties file in the advice folder. Change the paths in the build.properties if your configuration differs from mine. We also have to add the deployment descriptors to a folder named META-INF in the classes folder as this:
The ejb-jar.xml is the same as in Head First EJB. weblogic-ejb-jar.xml is an additional descriptor used by Weblogic and in this case it only include a simple mapping between the Bean-name AdviceBean and the JNDI-name Advisor.
7. Now are we ready to compile the source-files. I open a command prompt and cd to the advice directory. Then I invoke the ant build script with "ant build" to compile the files. C:\>cd projects\advice C:\project\advice>ant build This will put Advice.class, AdviceBean.class and AdviceHome.class in the classes/headfirst folder. 8. weblogic.appc compiler is the recommended approach for EJB compliation in WebLogic Server 8.1. It will examine the compiled classes and the deployment descriptors and create the stubs and the container generated implementations of the interfaces for us. I use "ant appc" to invoke the weblogic.appc. Please see the build.xml file to see how this is working.
C:\project\advice>ant appc This will put all the container generated files in the classes/headfirst folder.
9. We are now ready to make a deployable jar-file of the classes in the headfirst folder and the deployment descriptors in the META-INF folder. I use "ant makejar" to make the jar. C:\project\advice>ant makejar This will create a jar file named AdviceApp.jar in the advice folder. 10. Deploy the AdviceApp.jar to the weblogic server. a) Go to Start/Program/Bea WebLogic Platform 8.1/User Projects/mydomain/Start Server b) Open a webbrowser and go to http://localhost:7001/console c) Login using the password given when you created the domain (weblogic) d) Go to deployments/EJB Modules and choose Deploy a new EJB Module e) Choose upload your file(s) and upload the AdviceApp.jar. f) Click on "myserver" and then on "upload" select AdviceApp.jar and click "Target Module". e) Review your choices and click deploy. Hopefully the bean will be deployed sucessfully.
11. Create a client to test the bean. One difference between the Sun RI and Weblogic Server is that you have to specify how to get hold of the InitialContext. This can be done like this for Weblogic: -------- Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ic = new InitialContext(properties); -------- A AdviceClient.java i provided in the advice.zip. Copy it to the advice directory. Invoke "ant buildclient" to compile the client. Notice that I have named the business method getMessage() instead of getAdvice(). C:\project\advice>ant buildclient Basicly this as the rest of the build scripts are very simple. It will compile AdviceClient.java to AdviceClient.class in the same directory. This can of course be done with javac, just be sure to include $BEA_HOME/weblogic81/server/lib/weblogic.jar and AdviceApp.jar in the classpath. I'm using the AdviceApp.jar, the same as we used to deploy the bean, to make the stubs and interfaces availible to the the client. AdviceApp.jar includes more than the client needs (the bean and server side implementations of the interfaces) but it is easier in this case. 12. Run the client. To run the client you can use the "ant run" command (make sure the server is running). C:\project\advice>ant run Another way is to use the run.bat included i advice.zip like this: C:\project\advice>run Please see the build.xml or the run.bat to see how it works. [ December 14, 2003: Message edited by: Magnus Stattin ]
Every application server has its own way to get the initial context. So the properties you have to specify is different. The reason why the client for the RI is simpler and seems to be generic is the default values happens to be sufficient as long as the client is located at the same server as the EJB is deployed. /Magnus