简体   繁体   中英

using EJB from within an applet

I have been trying to inject/use my EJB from within an applet without success. I have created a new Java EE Enterprise application. I am using glassfish 3 & netbeans 7.1

The main problem has been instantiating InitialContext .

Here are the declarations of my beans.

   @Stateless
   public class UserFacade implements UserFacadeLocal {
   @PersistenceContext(unitName = "MetroEntitiesPU")
   private EntityManager em;

   @Remote
   public interface UserFacadeLocal {

I have been able to create a stand alone Java client by including the gf-client.jar class-path and using the following code.

try {
   UserFacadeLocal ufl = (UserFacadeLocal) new InitialContext()
     .lookup("bidd.data.ejb.UserFacadeLocal");
   System.out.println("FROM EJB COUNT: " + String.valueOf(ufl.count()));
} catch (NamingException ex) {
    Logger.getLogger(JavaApplication3.class.getName())
      .log(Level.SEVERE, null, ex);
}

The problem is when i am trying to do the same in the applet. The applet is compiled in a jar file and then loaded from a jsp website which is part of my enterprise application in netbeans.

This is the line in the init method that gives the error that follows.

UserFacadeLocal ufl = (UserFacadeLocal) new InitialContext()
  .lookup("bidd.data.ejb.UserFacadeLocal");

Error

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

How to solve this error?

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
  • environment or system property
    Not practical for a publicly deployed applet 1 .
  • as an applet parameter
    Should be trivial 1 . Something like:
    <applet ..><param name='the.name' value='bidd.data.ejb.UserFacadeLocal'> </applet>
  • in an application resource file
    Might be workable, but presumably you need to add a param to identify the file.

  1. applet: The same applies to JWS apps., which is what I actually recommend for this deployment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM