Java – how to develop and run ejb in netbean6.7

ejb-3.0javanetbeans

I am beginner of studying EJB . I want to test very very small ejb application in netbean 6.7. The code are as follows

package jeenptbeans;
import javax.ejb.Remote;
@Remote
public interface NewSessionRemote {
    public String getEchoString(String clientString);

}

package jeenptbeans;
import javax.ejb.Stateless;

@Stateless
public class NewSessionBean implements NewSessionRemote, NewSessionLocal {

 public String getEchoString(String clientString) {
return clientString + " - from session bean";
}
 public String getdisString(String clientString) {
return clientString + " - from session bean";
}

So , I created File–>New Project–>EJB module .And Right click the project and choose New–>Session bean and add above code.But I run this project, "build successfully" message is shown.So I want to test this bean with client application. So I made "Enterprise Application Client" app and add ejb as follows.

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.NamingException;
import jeenptbeans.NewSessionRemote;
import javax.naming.InitialContext;
import jeenptbeans.NewSessionBean;

public class Main {
    @EJB
    private static NewSessionRemote newSessionBean;
   public static void main(String[] args) {
        try {
              InitialContext ctx = new InitialContext();
             newSessionBean = (NewSessionBean)ctx.lookup(NewSessionBean.class.getName());

            for (int i = 0; i < args.length; i++) {
            String returnedString = newSessionBean.getEchoString(args[i]);
            System.out.println("sent string: " + args[i] +
            ", received string: " + returnedString);
            }
        } catch (NamingException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

But when I run this client application ,I got the following exceptions.


"SEC5046: Audit: Authentication refused for [admin].
Web login failed: Login failed: javax.security.auth.login.LoginException: Failed file login for admin.
CORE5024: EJB module [JEENPT-SessionEJB1] unloaded successfully!
deployed with moduleid = JEENPT-SessionEJB1
**RemoteBusinessJndiName: jeenptbeans.NewSessionRemote; remoteBusIntf: jeenptbeans.NewSessionRemote
LDR5010: All ejb(s) of [JEENPT-SessionEJB1] loaded successfully!
ADM1006:Uploading the file to:[C:\Documents and Settings\Yamin\Local Settings\Temp\s1astempdomain1server1142715591\JEENPT-AppEJBClient1.jar]
Class [ jeenptbeans/NewSessionRemote ] not found. Error while loading [ class jeenptappejbclient1.Main ]
Error in annotation processing: java.lang.NoClassDefFoundError: jeenptbeans/NewSessionRemote
deployed with moduleid = JEENPT-AppEJBClient1
Registering ad hoc servlet: WebPathPath: context root = "/JEENPT-AppEJBClient1", path = "'
Java Web Start services started for stand-alone app client com.sun.enterprise.appclient.jws.AppclientContentOrigin@1bb5013 registration name=JEENPT-AppEJBClient1, context root=/JEENPT-AppEJBClient1, module name=
CORE5024: EJB module [JEENPT-SessionEJB1] unloaded successfully!
deployed with moduleid = JEENPT-SessionEJB1
**RemoteBusinessJndiName: jeenptbeans.NewSessionRemote; remoteBusIntf: jeenptbeans.NewSessionRemote
LDR5010: All ejb(s) of [JEENPT-SessionEJB1] loaded successfully!
classLoader = WebappClassLoader
  delegate: false
  repositories:
----------> Parent Classloader:
WebappClassLoader
  delegate: true
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
EJBClassLoader : 
urlSet = []
doneCalled = false 
 Parent -> java.net.URLClassLoader@103de90
SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@cf10ae
Java Web Start services ended for stand-alone app client com.sun.enterprise.appclient.jws.AppclientContentOrigin@1bb5013 registration name=JEENPT-AppEJBClient1, context root=/JEENPT-AppEJBClient1, module name=
ADM1064:The upload file at [C:\Documents and Settings\Yamin\Local Settings\Temp\s1astempdomain1server1142715591\JEENPT-AppEJBClient1.jar] exists and will be overwritten.
ADM1006:Uploading the file to:[C:\Documents and Settings\Yamin\Local Settings\Temp\s1astempdomain1server1142715591\JEENPT-AppEJBClient1.jar]
Class [ jeenptbeans/NewSessionRemote ] not found. Error while loading [ class jeenptappejbclient1.Main ]
Error in annotation processing: java.lang.NoClassDefFoundError: jeenptbeans/NewSessionRemote
deployed with moduleid = JEENPT-AppEJBClient1
Registering ad hoc servlet: WebPathPath: context root = "/JEENPT-AppEJBClient1", path = "'
Java Web Start services started for stand-alone app client com.sun.enterprise.appclient.jws.AppclientContentOrigin@db05a8 registration name=JEENPT-AppEJBClient1, context root=/JEENPT-AppEJBClient1, module name=
CORE5024: EJB module [JEENPT-SessionEJB1] unloaded successfully!
classLoader = WebappClassLoader
  delegate: false
  repositories:
----------> Parent Classloader:
WebappClassLoader
  delegate: true
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
EJBClassLoader : 
urlSet = []
doneCalled = false 
 Parent -> java.net.URLClassLoader@103de90
SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@cf10ae
Java Web Start services ended for stand-alone app client com.sun.enterprise.appclient.jws.AppclientContentOrigin@db05a8 registration name=JEENPT-AppEJBClient1, context root=/JEENPT-AppEJBClient1, module name=
ADM1064:The upload file at [C:\Documents and Settings\Yamin\Local Settings\Temp\s1astempdomain1server1142715591\JEENPT-AppEJBClient1.jar] exists and will be overwritten.
ADM1006:Uploading the file to:[C:\Documents and Settings\Yamin\Local Settings\Temp\s1astempdomain1server1142715591\JEENPT-AppEJBClient1.jar]
Class [ jeenptbeans/NewSessionRemote ] not found. Error while loading [ class jeenptappejbclient1.Main ]
Error in annotation processing: java.lang.NoClassDefFoundError: jeenptbeans/NewSessionRemote
deployed with moduleid = JEENPT-AppEJBClient1
Registering ad hoc servlet: WebPathPath: context root = "/JEENPT-AppEJBClient1", path = "'
Java Web Start services started for stand-alone app client com.sun.enterprise.appclient.jws.AppclientContentOrigin@8500bc registration name=JEENPT-AppEJBClient1, context root=/JEENPT-AppEJBClient1, module name=


Please help me. Is this right or wrong making "Enterprise Application Client" application to test simple session bean? I also don't know where to add parameters for main function. To test this very simple ejb with netbean 6.7, please teach me the steps to follow. Thanks a lot.

Best Answer

One area in which NetBeans is very good is Documentation, Training & Support (and Community Docs). Here, I'd suggest to check Creating EJB3 Sessions Beans using Netbeans 6.1 and Glassfish (as written at the bottom of the page, "Works with NetBeans 6.0,6.5,6.1,6.7,6.7.1").

Regarding the Enterprise Application Client feature, it should be ok but I don't have any experience with it (I wonder how such a project works outside of NetBeans). I'd just use a standard Java client.