10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

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.

}<br />

public BigDecimal yenToEuro(BigDecimal yen) {<br />

BigDecimal result = yen.multiply(euroRate);<br />

return result.setScale(2, BigDecimal.ROUND_UP);<br />

}<br />

Note the @Stateless annotation decorating the enterprise bean class. This lets the container<br />

know that ConverterBean is a stateless session bean.<br />

Compiling and Packaging the converter Example<br />

Now you are ready to compile the remote business interface (Converter.java) and the<br />

enterprise bean class (ConverterBean.java), and package the compiled classes into an<br />

enterprise bean JAR.<br />

Compiling and Packaging the converter Example in NetBeans IDE<br />

Follow these instructions to build and package the converter example in NetBeans IDE.<br />

1. In NetBeans IDE, select File→Open Project.<br />

2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/ejb/.<br />

3. Select the converter folder.<br />

4. Select the Open as Main Project and Open Required Projects check boxes.<br />

5. Click Open Project.<br />

6. In the Projects tab, right-click the converter project and select Build. You will see the<br />

output in the Output tab.<br />

Compiling and Packaging the converter Example Using Ant<br />

To compile and package converter using Ant, do the following:<br />

1. In a terminal window, go to this directory:<br />

tut-install/javaeetutorial5/examples/ejb/converter/<br />

2. Type the following command:<br />

ant<br />

Creating the Enterprise Bean<br />

This command calls the default task, which compiles the source files for the enterprise bean<br />

and the application client, placing the class files in the build subdirectories (not the src<br />

directory) of each submodule. <strong>The</strong>n the default task packages each submodule into the<br />

appropriate package file: converter-app-client.jar for the application client,<br />

converter-ejb.jar for the enterprise bean JAR, and converter-war.war for the web client.<br />

<strong>The</strong> web client in this example requires no compilation. For more information about the Ant<br />

tool, see “Building the Examples” on page 69.<br />

Chapter 21 • Getting Started with Enterprise Beans 645

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

Saved successfully!

Ooh no, something went wrong!