刚刚做了个JBoss入门:报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这样的错,
求解决方案,在此谢过java代码:-------------------------------------------------------package com.sls.ejb3;public interface HelloEJB3 {
public String sayHello(String name);
}-------------------------------------------------------package com.sls.ejb3.impl;import javax.ejb.Remote;
import javax.ejb.Stateless;import com.sls.ejb3.HelloEJB3;@Stateless
@Remote(HelloEJB3.class)
// @Stateless 这个注解可以指定类是个无状态的会话bean
public class HelloEjb3Bean implements HelloEJB3 { @Override
public String sayHello(String name) {
return name + "说:你好,世界....";
}}-------------------------------------------------------
客户端代码:
public static void main(String[] args) {
// Properties props = new Properties();
// props.setProperty("java.namint.jactory.initial",
// "org.jnp.interfaces.NamingContextFactory");
// props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx;
try {
ctx = new InitialContext();
System.out.println("110" + ctx);
HelloEJB3 helloEJB3 = (HelloEJB3) ctx
.lookup("java:helloEjb3/HelloEjb3Bean/remote");
System.out.println(helloEJB3.getClass().getName());
// System.out.println(helloEJB3.sayHello("尚立帅"));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}-------------------------------------------------------
jndi.properties代码:java.namint.jactory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
求解决方案,在此谢过java代码:-------------------------------------------------------package com.sls.ejb3;public interface HelloEJB3 {
public String sayHello(String name);
}-------------------------------------------------------package com.sls.ejb3.impl;import javax.ejb.Remote;
import javax.ejb.Stateless;import com.sls.ejb3.HelloEJB3;@Stateless
@Remote(HelloEJB3.class)
// @Stateless 这个注解可以指定类是个无状态的会话bean
public class HelloEjb3Bean implements HelloEJB3 { @Override
public String sayHello(String name) {
return name + "说:你好,世界....";
}}-------------------------------------------------------
客户端代码:
public static void main(String[] args) {
// Properties props = new Properties();
// props.setProperty("java.namint.jactory.initial",
// "org.jnp.interfaces.NamingContextFactory");
// props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx;
try {
ctx = new InitialContext();
System.out.println("110" + ctx);
HelloEJB3 helloEJB3 = (HelloEJB3) ctx
.lookup("java:helloEjb3/HelloEjb3Bean/remote");
System.out.println(helloEJB3.getClass().getName());
// System.out.println(helloEJB3.sayHello("尚立帅"));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}-------------------------------------------------------
jndi.properties代码:java.namint.jactory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
解决方案 »
- 关于quartz配置问题
- 新手帖:关于工作流
- 跳槽深圳工资
- 浓郁hibernate自定义数据类型!急啊
- struts标签显示数据问题
- 朋友,你能解决这个问题吗?
- 关于struts2寻找匹配action过程的疑问
- rmi 连接sql server2000数据库报错 classNotFound 和no suitable driver 的错误
- 在Eclipse中通过Lomboz-J2EE wizard创建的Project中创建JSP文件报错!!真郁闷
- java的jaxp包中如何调用XPointer功能--即象Microsoft的xmldom中的selectNodes("person[@age=1]");
- 请问下数据缓存池(hibernate,mybatis)
- jsp页面连接sql server时,提示早不到合适的驱动
改为
HelloEJB3 helloEJB3 = (HelloEJB3) ctx.lookup("HelloEjb3Bean/remote")
试下
改为
HelloEJB3 helloEJB3 = (HelloEJB3) ctx.lookup("HelloEjb3Bean/remote")
也不行啊!
helloEJB3没值啊!
我觉得还是ctx.lookup("HelloEjb3Bean/remote")这儿有问题啊!
求高手赐教!谢谢了
这是发布后的的名称。
我用这个也试过但也不行
这个帖子应该可以帮助你确定问题
| +- remote-com.sls.ejb3.HelloEJB3 (class: Proxy for: com.sls.ejb3.HelloEJB3)
| +- remote (class: Proxy for: com.sls.ejb3.HelloEJB3)
这是管理页面的代码,名称是HelloEjb3Impl,我用这个也不行啊!
package touch.test.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import touch.portal.interfaces.BeanRemoteInterface;
public class BeanClient {
private static Context getJBossInitialContext() {
Context context = null;
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "jnp://ServerTest:1099");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
context = new InitialContext(properties);
} catch (NamingException e) {
System.out.println("Can not connect JBoss Server : ServerTest:1099");
}
return context;
}
public static void main(String[] args) {
try {
Context context = getJBossInitialContext();
Object object = context.lookup("PortalBean/remote-touch.portal.interfaces.BeanRemoteInterface");
BeanRemoteInterface portalBean = (BeanRemoteInterface) object;
String strRtn = portalBean.getResult("{\"SERVCOM\":\"DutAddQueue\",\"SERVPARAM\":{},\"SERVMETHOD\":\"qry\"}");
System.out.println(strRtn);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
BeanRemoteInterface portalBean = (BeanRemoteInterfae) object
我的主要是object这个对象出不来啊!
我很是纠结,
package touch.portal.interfaces;
import javax.ejb.Remote;
@Remote
public interface BeanRemoteInterface {
public String getResult(String strArg);
}
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");try {
Context ctx = new InitialContext(jndiProperties);
System.out.println("110" + ctx);
HelloEJB3 helloEJB3 = (HelloEJB3)
ctx.lookup("java:/你的项目名/HelloEjb3Bean!com.sls.ejb3.HelloEjb3");
System.out.println(helloEJB3.getClass().getName());
// System.out.println(helloEJB3.sayHello("尚立帅"));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}在客户端src目录新建个jboss-ejb-client.properties里面代码
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=falseremote.connections=defaultremote.connection.default.host=localhostremote.connection.default.port = 4447remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false