[jboss-dev-forums] [Design of JBoss Eclipse IDE (dev)] - How to Lookup a session bean from a Javaclass/Servlet/jsp wi
AnuSree
do-not-reply at jboss.com
Thu Apr 12 07:23:39 EDT 2007
Hi,
I have written stateless session bean in EJB 3.0 Project(JBoss 4.0.5) using JBossIDE for Eclipse,Version: 2.0.0,Build id: 2.0.0.Beta2
And then packaged into calculator.jar
Then i have created a Application client and calculator.jar is added to it's library.
This is the code for SesionBean
package trail.bean;
|
| import javax.ejb.Remote;
| import javax.ejb.Stateless;
| import trail.bean.Calculator;
| import org.jboss.annotation.ejb.RemoteBinding;
|
| @Remote ({Calculator.class})
| @RemoteBinding (jndiBinding="EJB3Trail/Calculator")
| public @Stateless class CalculatorBean implements Calculator {
| public double calculate(int start, int end, double growthrate, double saving) {
| System.out.println("Inside calculate");
| double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1);
| double val=saving * 12. * (tmp - 1) / growthrate;
| System.out.println("return Value:"+val);
| return saving * 12. * (tmp - 1) / growthrate;
| }
| }
This is the code for Main.Java in App Client
| import java.text.NumberFormat;
| import javax.naming.InitialContext;
| import trail.bean.*;
|
|
| public class Main {
| public static void main(String[] args) {
|
| Calculator cal = null;
|
| try {
| InitialContext ctx = new InitialContext();
| cal = (Calculator) ctx.lookup("EJB3Trail/Calculator");
| //cal=(Calculator)ctx.lookup(Calculator.class.getName());
|
| } catch (Exception e) {
| System.out.println("-----------------Exception inside Lookup:"+e);
| e.printStackTrace();
| }
| }
|
|
My problem is while running the Main.java it showing Error messge like this
Exception inside Lookup:javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at Main.main(Main.java:18)
Can anybody Help Me.How to Lookup a session bean from a Javaclass/Servlet/jsp with JBoss Server.I'm very new to JBoss and Eclipse
this code work well with SUN AppServer
Thanks for any help.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4036683#4036683
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4036683
More information about the jboss-dev-forums
mailing list