13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

512Chapter 23Deploying EJBsExample 23.5 Locating the home interface//Look up home interfaceInitialC<strong>on</strong>text initctxt = new InitialC<strong>on</strong>text();Object obj = initctxt.lookup("ejb/M<strong>on</strong>ey");M<strong>on</strong>eyHome homer = (M<strong>on</strong>eyHome) PortableRemoteObject.narrow(obj, M<strong>on</strong>eyHome.class);We’re putting this code in the init() method of a servlet; it could alsobe in a test program, or in a JSP. It needs to happen <strong>on</strong>ly <strong>on</strong>ce for our servlet(which is why we put it in the init() method) and then the c<strong>on</strong>necti<strong>on</strong> canbe used many times, <strong>on</strong>ce for each c<strong>on</strong>tact with the bean.We get to the actual bean this way:M<strong>on</strong>ey mrbean;mrbean = homer.create();We then use the bean, making the calls <strong>on</strong> its remote interface (a M<strong>on</strong>eyobject, that extends EJBObject) as if it were just a simple method call <strong>on</strong> anordinary class:car = mrbean.save(20000.00, 0.04, 250.00);The math is d<strong>on</strong>e in the actual Sessi<strong>on</strong>Bean, out there in the network,and the results are sent back to this applicati<strong>on</strong>. Our applicati<strong>on</strong> goes <strong>on</strong> todisplay this number as part of an HTML page.Then when we’re d<strong>on</strong>e with the bean, we need to clean up:mrbean.remove();23.2.3 Packaging the ServletWe will now package up the servlet, al<strong>on</strong>g with a simple startup page to invokeit. We’ll look at the WAR file and see how it’s built.23.2.3.1 What Is in the WAR FileThe other JAR-like file in the EAR is the WAR file. Let’s see what is in <strong>on</strong>e ofthose (Table 23.3).Notice that the WAR file puts its XML descriptor not in the META-INFdirectory but in a WEB-INF directory al<strong>on</strong>g with the classes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!