I am using netbeans IDE 7.1.2 and I have created an EJB 3.1 Stateless Bean and implemented remote as well as local interfaces both and deployed it to the glassfish server 3.2.1 successfully...here is the Code
_____________________CaseInfo.java__________________
enter code here
package maxx;
import javax.ejb.Stateless;
@Stateless(name="CaseInfo",mappedName="CaseInfoBean")
public class CaseInfo implements CaseInfoRemote, CaseInfoLocal {
@Override
public String MyCaseMessageLocal() {
return "Hello this is my Local message.";
}
@Override
public String MyCaseMessageRemote() {
return "Hello this is my Remote message.Please Note that this message is comming from the remote";
}
}
__________________CaseInfoLocal.java___________________
package maxx;
import javax.ejb.Local;
@Local
public interface CaseInfoLocal {
String MyCaseMessageLocal();
}
_________________CaseInfoRemote.java__________________
package maxx;
import javax.ejb.Remote;
@Remote
public interface CaseInfoRemote {
String MyCaseMessageRemote();
}
now i have accessed it from locally successfully and after it i have created
New Project>Java EE>Application Client project which is an desktop app hare i have accessed that bean successfully by adding jar file of bean module in to its library as a client Stub here is the some code
_____________________Main.java_____________________
package applicationclient;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import maxx.CaseInfoRemote;
public class Main {
public static void main(String arg[]) {
try {
Properties prop = new Properties();
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ic = new InitialContext(prop);
Object ref = ic.lookup("CaseInfoBean");
CaseInfoRemote home = (CaseInfoRemote)PortableRemoteObject.narrow(ref,
CaseInfoRemote.class);
System.out.println(home.MyCaseMessageRemote());
} catch(Exception e) {
e.printStackTrace();
}
}
}
but when I am using this client accessing code go to New Project>java>java Application and writing here the same code so the problem showing that
______________________ERROR_______________________
run:
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at testcasebean.TestCaseBean.main(TestCaseBean.java:30)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:63)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
... 4 more
BUILD SUCCESSFUL (total time: 0 seconds)
and if i am removing properties lines of code so is giving this type of ERROR
run: 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:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at testcasebean.TestCaseBean.main(TestCaseBean.java:27)
BUILD SUCCESSFUL (total time: 0 seconds)
please tell how can i access this bean through using simple java desktop application because its no problem to using Java EE application Client but same code is giving these error