Configure JBOSS to run from within Eclipse.First of all we have to configure the Java Development settings, because Lomboz requires different directories for source and binaries. Go to Window > Preferences > Java > New Project. Enter src and bin for the names of these folders, which are the defaults. Please do not modify these names as they are required by some of the Lomboz tasks. Also, make sure JRE library is set to 'JRE_LIB' variable. 
 Go to Window on top level menu > Preferences. 
 Go to the Lomboz node under the Preferences window. Make sure JDK Tools.jar is set to $JAVA_HOME/lib/tools.jar 
 Go to the server definitions sub node under Lomboz node. Select JBOSS 3.2.ALL under Server types and the rest of the options will be filled after loading the server configuration file which we made for this tutorial. 
 Now, under Server Definitions, go to 'Classpath' and make sure all the paths are correct. If there is a wrong setting for a path, it will show red crosses with jar icons in Server libraries / Client libraries sub section. 
 You can add or remove libraries from here. Make sure you 'Apply' the changes after altering the various options. And now verify your 'Classpath Variables'. Go to Window > Preferences > Java > Classpath Variables 
 If you get all these Classpath variables right according to your environment. Test your configuration.To test your configuration, create a J2EE Project as a test. Go to File at top level menu > New > Lomboz J2EE Project. 
 Enter 'Test' as project name and press Next. Check your settings here; if you have 'Test/src' on build path and 'Test/bin' under default output folders then it's ok. 
 Now click on Libraries tab on the Project Creation Wizard. Because of a bug in Eclipse 2.1 this library is configured wrongly. So select this library and Remove it. 
 Now, add a new library > Add Library.. > Select JRE System library > Next . 
 Select Default library and press Finish. 
 New library is configured. Note: You have to repeat this step whenever you are creating a new J2EE Project, as there is a bug in eclipse 2.1. Now press Next. Go to Web Module > Add.. > Enter Module Name 'OnlineBank' > Ok. 
 Go to Ejb Modules tab > Add.. > Enter Module Name 'MyBank' > Ok. 
 Go to Targeted Server > Add.. > 'JBOSS 3.2.1 ALL' . Note: 'JBOSS 3.2.1 ALL' is not the file name, but the name assigned to server in the 'jboss321all.server' file used for configuration showed above. Snippet from file below. 
 
 Press Finish. Now you will have all these directories and libraries under Test Project in the Package Explorer. Under Project Test 'src' is the directory where all packages for EJB components and Servlets will be developed, that is your java source files. The 'MyBank' directory is your EJB Module and will have 7 files at start shown in fig below. The 'OnlineBank' directory is your Web Module and will have 7 files shown in fig below. Your JSP pages will come under this directory for this module. Note: If you are interested in Ant (from the Jakarta Project) then note that both modules have an Ant 'build.xml' file which is used to build the application. 
 Now go to top level menu option Window > Show View > Lomboz J2EE View. Lomboz J2EE view will have Test Project , which has two modules 'MyBank' and 'OnlineBank' using JBOSS 3.2.1 as their default server. 
 Now it's time to create an EJB, Go to File > New > Lomboz EJB creation wizard. Note: You can access this wizard by right clicking in on project Test in Package Explorer. Go to New > Lomboz EJB creation wizard as explained in the beginning. Add package name 'au.com.tusc'; you can choose another name if you want. Add 'MySession' in Name. Select Stateless Session EJB option. 
 This will create a file 'MySessionBean.java' under the 'au.com.tusc' package as shown in figure below. Note: It will generate the bean name, jndi-name and type of bean in the file. Also the name of the file is appended with word 'Bean' as you gave the name of the bean as 'MySession' only. So be careful with naming conventions, as you only need to specify the bean name in the wizard. Don't append the word Bean to the name as the wizard will do that for you. 
 Now we will add a business method via the wizard. Go to file 'MySessionBean.java' under 'Package Explorer' and expand that, right click on 'MySessionBean' node as shown in the figure below, select New > Lomboz EJB Method wizard. In the method signature put 'public String learnJ2EE(String messg)', select method type as 'Business Method' and Interface Type as 'Remote Interface'. 
 This will generate the required signature for your business method in your bean class. Now add this line in this method "Me too! "; Code Snippet from Bean file  /**
  * @ejb.interface-method
  * tview-type="remote"
  *
  **/
     public  String learnJ2EE  (String messg)  { 
         return "Me too! ";
     }
Save the file. Now we will generate the rest of the files (Home and Remote interfaces along with helper classes, using Xdoclet) required to deploy this bean. First add this Bean to the module. Go to Package Explorer > Test > MySessionBean.java > MySessionBean, right click on that; a menu will pop up. Go to Lomboz J2EE on this pop-up menu, and select 'Add EJB to module'. 
 Go to Package Explorer > Test > MyBank (which is a directory), right click on that; a menu will pop up. Go to Lomboz J2EE, which is at the bottom of this pop up menu. Select Generate EJB classes. This will generate the required interfaces, helper classes and files related to deployment; that is, deployment descriptors. 
 It will create a new directory named ejbsrc, which will have a package named au.com.tusc, and under that, remote and home interfaces, along with necessary helper classes, will be generated. Note: You will not edit any files generated by Xdoclet under 'ejbsrc' directory at any time while doing this tutorial. Because every time you use option Generate EJB Classes, it generates the necessary interfaces and helper classes as mentioned above. These files are generated by Xdoclet, after parsing your bean class, which is created by Lomboz bean creation wizard. Xdoclet looks at the various declared tags and methods in the bean class and then generates files accordingly. As a result, you just add business methods and their implementations in the bean class, and the rest is left to Xdoclet. Hence at any time in the development, you won't need to (and shouldn't!) edit any generated files. It will become clearer as we progress in this tutorial. Also under MyBank > META-INF directory now there are 15 files, which includes ejb-jar.xml and jboss.xml and ejb-generate.xml. Initially there were only 6 files as noted earlier. These extra files are needed for deployment of the bean. 
 Now let us deploy this bean without going into any further details of deployment. Go to Lomboz J2EE view in your workspace, expand Test > expand MyBank. You will have au.com.tusc.MySessionBean added to your MyBank EJB module. Right click on JBOSS 3.2.1 ALL icon as shown in fig below. 
 A menu will pop up; select option Debug Server. It will start the server with Debug mode and after successful start it will show this message in the console under your workspace as shown in the figure below. 
 Go to Lombo J2EE View > expand Test > select MyBank and right click on that; a menu will pop up; select option Deploy. 
 Once the bean is deployed, a message will come in your 'Console' confirming that, as shown in the figure below. 
 Now we will create a client to access this bean deployed on JBOSS (application sever). Go to Package Explorer > Test > src, right click on that, a menu will pop up > select EJB Test client. Enter Package name 'test' and Client name as 'Client'. 
 Select EjbHome as 'MySessionHome' and Ejb Interface as 'MySession' > Finish as shown in the figure below. 
 Now the client is generated, it's time to call business methods on the deployed bean. We need some code to invoke the method on the bean.. 
 Go to Client.java and write these lines under the 'testBean()' method. String request = "I'm tired of 'Hello, world' examples.."; System.out.println("Request from client : " + request); System.out.println("Message from server : " + myBean.learnJ2EE(request) ); 
      public void testBean() {
         try {
               au.com.tusc.MySession myBean = getHome().create();
               //--------------------------------------
                //This is the place you make your calls.
                //System.out.println(myBean.callYourMethod());
               String request = "I'm tired of 'Hello, world' examples..";
               System.out.println("Request from client : " + request);
               System.out.println("Message from server : " + myBean.learnJ2EE(request) );
          } catch (RemoteException e) {
                 e.printStackTrace();
          } catch (CreateException e) {
                 e.printStackTrace();
          } catch (NamingException e) {
                 e.printStackTrace();
          }
     }
Now first select Client node under Package Explorer. Go to top level menu and select this icon as shown below. 
 
 Your Client is going to make a request, the results of which will be displayed in the console under your workspace, as shown below. 
 Note: Ignore these exceptions regarding org.apache.log4j.Property as it requires 'log4j.properties' on the clients path. We will cover this later on as this doesn't affect the functioning of the bean. You have successfully created a bean and invoked an operation on it. Now, let's have a brief overview of J2EE concepts in the next chapter, before we start implementing the case study. 
   | 相关文章: 相关软件:  | 
  















































