| |
Install Interest Example
JBoss Interest
example converted to Eclipse projects.
- Click File, click Import..., click Existing Project into Workspace, click
Next, click Browse..., navigate to C:\eclipse\workspace\interestejb, click
Finish.
- Click File, click Import..., click Existing Project into Workspace, click
Next, click Browse..., navigate to C:\eclipse\workspace\interestweb, click
Finish.
- Click File, click Import..., click Existing Project into Workspace, click
Next, click Browse..., navigate to C:\eclipse\workspace\interestclient, click
Finish.
- Expand interestweb project in Eclipse.
- Right click on build.xml, click Run Ant..., check ear-dir, jar-dir and
war-dir, click Finish.
- 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.
- 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>
Save changes and exit Wordpad.
Working with the Interest Example in Eclipse
- 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.
 | interestejb 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. |
 | interestweb 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. |
 | interestclient 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. |
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.
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
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
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.
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
Notice that the code automatically compiled and the change showed up right
away. Now let's change an EJB.
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.
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.
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
Notice that the amount changed as a result of changing the calculation
code.
Debugging Interest Example in Eclipse
- Open the InterestServlet.java code in the interestweb project..
- On line 72 double-click in the gray area immediately adjacent to set a
break point.
- 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.
- Click Resume and switch back to Java perspective.
- Open the InterestBean.java code in the interestejb project..
- On line 25 double-click in the gray area immediately adjacent to set a
break point.
- 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.
- Click Resume and switch back to Java perspective.
- This concludes our simple debugging example.
|