Interest

Install Interest Example

JBoss Interest example converted to Eclipse projects.

  1. Click File, click Import..., click Existing Project into Workspace, click Next, click Browse..., navigate to C:\eclipse\workspace\interestejb, click Finish.
  2. Click File, click Import..., click Existing Project into Workspace, click Next, click Browse..., navigate to C:\eclipse\workspace\interestweb, click Finish.
  3. Click File, click Import..., click Existing Project into Workspace, click Next, click Browse..., navigate to C:\eclipse\workspace\interestclient, click Finish.
  4. Expand interestweb project in Eclipse.
  5. Right click on build.xml, click Run Ant..., check ear-dir, jar-dir and war-dir, click Finish.
  6. Click interestweb project, click Project, click Rebuild Project.  If you are just working with just the Servlet code you do not need to run the Ant script again.  If you want to update the deployment with EJB classes run only the jar-dir target.
  7. From My Computer navigate to %JBOSS_DIST%\server\default\conf, open jboss-service.xml in Wordpad, go to line with:
        <attribute name="URLs">
        ./deploy
        </attribute>


    Right after ./deploy add ,C:\eclipse\workspace\interestweb\interest.ear so it should look like:

        <attribute name="URLs">
        ./deploy,
        C:\eclipse\workspace\interestweb\interest.ear
        </attribute>
  8. Save changes and exit Wordpad.

Working with the Interest Example in Eclipse

  1. Run Eclipse, in Package Explorer you should see interestclient, interestejb and interestweb.  This structure allows for seperate editing, deployment and version control of each component.
    bulletinterestejb contains all the EJBs for the Interest Example.  It uses the project as the source folder, has one package org.jboss.docs.interest which contains the EJB source.
    bulletinterestweb contains the Servlet code.  It uses one source folder src, has one package org.jboss.docs.interest which contains the Servlet source.  The output is directed to interestweb/interest.ear/interest.war/WEB-INF/classes which allows hot editing of the Servlet without having to deploy it (compiling the source deploys the classes for you).  The interest.ear folder is an exploded ear file (uses the same structure as an ear).  In step 4 of Install Interest Example we are directing the JBoss auto deployer to see C:\eclipse\workspace\interestweb\interest.ear.  It makes sense to locate the ear folder here since most of the changes will happen with the Servlet and client code.
    bulletinterestclient contains an EJB console client.  It uses the project as the source folder, has one package org.jboss.docs.interest which contains the client source and a jndi.properties file.  You will notice that since the client runs outside the JBoss process that is requires all the client jars.
  2. Click JBoss, Start JBoss and wait for:

    10:33:48,077 INFO [Server] JBoss (MX MicroKernel) [3.0.1RC1 Date:200206291622] Started in 0m:12s:125ms

    in the Console output.  This means JBoss is up and running.
  3. Open a web Browser and go to http://localhost:8080/interest, you should see the Interest EJB Form.  Click on Calculate and you should see:

    Servlet interface to EJB

    Calling EJB...

    Interest on 1000.0 units, at 10.0% per period, compounded over 2.0 periods is: 210.00000000000023
     

  4. Now let's try running the interest client.  Click Run, Run..., click on Java Application, click New, put InterestClient in Name, click Browse... and select interestclient, click OK, click Search..., select InterestClient, click OK and click Run.

    select interestclient and click Run.  You should see:     

    Got context
    Got reference
    Interest on 1000 units, at 10% per period, compounded over 2 periods is:
    210.00000000000023

  5. Now that we verified everything working we can move on to modifying the code.  On the interestweb project navigate to src, org.jboss.docs.interest and double-click on InterestServlet.java.  Change line 67 from:

    out.println("<H2>Calling EJB...</H2>");

    to:

    out.println("<H2>Calling EJB, right now...</H2>");

    click on Save Editor Contents.
  6. Open a web Browser and go to http://localhost:8080/interest, you should see the Interest EJB Form.  Click on Calculate and you should now see:

    Servlet interface to EJB

    Calling EJB, right now...

    Interest on 1000.0 units, at 10.0% per period, compounded over 2.0 periods is: 210.00000000000023
     

  7. Notice that the code automatically compiled and the change showed up right away.  Now let's change an EJB.
  8. On the intrestejb project open package org.jboss.docs.interest, double-click on InterestBean.java.  Change line 26 from:

    return principle * Math.pow(1+rate, periods) - principle;

    to:

    return principle * Math.pow(1+rate, periods) - principle * .01;

    click on Save Editor Contents.
  9. Right click on build.xml, click Run Ant..., check deploy-classes, click Finish.  This deployed your EJB classes to the interest.ear folder in the interestweb project.
  10. Open a web Browser and go to http://localhost:8080/interest, you should see the Interest EJB Form.  Click on Calculate and you should now see:

    Servlet interface to EJB

    Calling EJB, right now...

    Interest on 1000.0 units, at 10.0% per period, compounded over 2.0 periods is: 1200.0000000000002
     

  11. Notice that the amount changed as a result of changing the calculation code.

Debugging Interest Example in Eclipse

  1. Open the InterestServlet.java code in the interestweb project..
  2. On line 72 double-click in the gray area immediately adjacent to set a break point.
  3. Open a web Browser and go to http://localhost:8080/interest, you should see the Interest EJB Form.  Click on Calculate and Eclipse should switch to debug perspective and you will be able to step through the Servlet.
  4. Click Resume and switch back to Java perspective.
  5. Open the InterestBean.java code in the interestejb project..
  6. On line 25 double-click in the gray area immediately adjacent to set a break point.
  7. Open a web Browser and go to http://localhost:8080/interest, you should see the Interest EJB Form.  Click on Calculate and Eclipse should switch to debug perspective and you will be able to step through the EJB code.
  8. Click Resume and switch back to Java perspective.
  9. This concludes our simple debugging example.
Home | JBoss Examples Last updated on 08/07/2002