Please help: Failed to run simple EJB 3.0 Application
mathias.altmeyer Aug 14, 2006 3:11 AMHello.
I'm trying to deploy a simple EJB 3.0 application within JBoss Application Server (build CVSTag=JBoss_4_0_4_GA date=200605151000). Here is my sample code:
Remote Interface:
import java.math.BigDecimal;
import javax.ejb.Remote;
@Remote
public interface Converter {
public BigDecimal dollarToYen(BigDecimal dollars);
public BigDecimal yenToEuro(BigDecimal yen);
}
Bean class:
import javax.ejb.Stateless;
import java.math.BigDecimal;
@Stateless
public class ConverterBean implements Converter
{
private BigDecimal euroRate = new BigDecimal("0.0070");
private BigDecimal yenRate = new BigDecimal("112.58");
public BigDecimal dollarToYen(BigDecimal dollars) {
BigDecimal result = dollars.multiply(yenRate);
return result.setScale(2, BigDecimal.ROUND_UP);
}
public BigDecimal yenToEuro(BigDecimal yen) {
BigDecimal result = yen.multiply(euroRate);
return result.setScale(2, BigDecimal.ROUND_UP);
}
}
Test client:
import java.math.BigDecimal;
import javax.ejb.EJB;
import javax.naming.*;
public class ConverterClient
{
public ConverterClient()
{
}
public static void main(String[] args)
{
ConverterClient client = new ConverterClient();
client.doConversion();
}
public void doConversion()
{
try {
InitialContext ctx = new InitialContext();
Converter converter = (Converter)
ctx.lookup("converter/ConverterBean/remote");
BigDecimal param = new BigDecimal("100.00");
BigDecimal yenAmount = converter.dollarToYen(param);
System.out.println("$" + param + " is " + yenAmount + " Yen.");
BigDecimal euroAmount = converter.yenToEuro(yenAmount);
System.out.println(yenAmount + " Yen is " + euroAmount + " Euro.");
System.exit(0);
} catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}
My JNDI properties file:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
My ear archive (named converter.ear) has the following content:
META-INF/application.xml
beans.jar
My beans.jar has the following content:
Converter.class
ConverterBean.class
After deploying the archive JBoss don't has created the context path "converter/ConverterBean/remote"! After compiling and running the test client I get an NameNotFoundException:
javax.naming.NameNotFoundException: converter not bound
I thought that I don't need a deployment descriptor anymore. Is my ear archive incorrect? What is my fault? Please help me!
Thank you! Mathias