我是学习EJB的初学者。我想在netbean 6.7中测试非常小的ejb应用程序。代码如下
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";
}
所以,我创建了File - > New Project - > EJB模块。右键单击项目并选择New - > Session bean并添加上面的代码。但是我运行这个项目,“build successfully”消息显示。所以我想用客户端应用程序测试这个bean。所以我制作了“企业应用程序客户端”应用程序,并按如下方式添加了ejb。
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);
}
}
}
但是当我运行这个客户端应用程序时,我遇到了以下例外情况。
"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=
请帮帮我。这是对还是错,使“企业应用程序客户端”应用程序测试简单的会话bean?我也不知道在哪里添加main函数的参数。要使用netbean 6.7测试这个非常简单的ejb,请教我遵循的步骤。非常感谢。
答案 0 :(得分:1)
NetBeans非常好的一个领域是Documentation, Training & Support(和Community Docs)。在这里,我建议检查Creating EJB3 Sessions Beans using Netbeans 6.1 and Glassfish(如页面底部所示,“使用 NetBeans 6.0,6.5,6.1,6.7,6.7.1 ”< / em>的)。
关于Enterprise Application Client功能,应该可以,但我没有任何使用经验(我想知道这样的项目是如何在NetBeans之外工作的)。我只是使用标准的Java客户端。