Sun Java System Application Server
|
Samples
Index
The Java EE 5 Annotation Sample Application - Java Client
Standalone Java Client
Here's an example of a plain Java client that runs outside of a Java EE
container. In this case, it does a global JNDI lookup
since
dependency injection is not available outside of a Java EE component.
public class JavaClient {
public static void main(String args[]) {
try {
InitialContext ic = new InitialContext();
Lottery lottery = (Lottery)
ic.lookup("enterprise.lottery_annotation_ejb_stateful.Lottery");
Dice
dice;
for(int i=0; i<5; i++) {
dice = (Dice)
ic.lookup("enterprise.lottery_annotation_ejb_stateless.Dice");
lottery.select(dice.play());
}
String lotteryName = lottery.getName();
String lotteryNumber = lottery.getNumber();
String lotteryDate = lottery.getDate();
String results = "Your" + " " + lotteryName + " " + "quick pick, played
on" +
" " + lotteryDate + " " + "is" + " " + lotteryNumber;
System.out.println(results);
} catch(Exception e) {
System.out.println("Exception: " + e);
e.printStackTrace();
}
}
}
Bean's business interface
class name is used for its lookup. No need to assign/use explicit JNDI
name
for the bean.
Building, Deploying, and Running the Java Client
Following are the instructions for building, deploying, and running
the Java Client.
- Setup your build environment and Configure the application
server with which the build system has to work by following the
common build instructions.
- Change directory to
client_dir
of the
Lottery sample application, which is
samples_install_dir/javaee5/enterprise/lottery-annotation-ear/lottery-annotation-appclient
- Build, and Run the java client using the target
run
client_dir>
ant
run
Make sure that the application is built
and deployed prior to running this target.
In build.xml, the property
'extra.classpath' points to ejb
classes on which this client code depends and the property
'runjavaclient.class.name' points to the Java Client class name which
is invoked as a result of running ant run
.
- Use the target
clean
to remove the temporary
directories like build
and dist
.
client_dir> ant
clean
Troubleshooting
If you have problems when running the application, refer to
troubleshooting document.
Copyright © 2006 Sun
Microsystems, Inc.
All rights reserved.