试一试吧,记得先将JBuilder6和WebLogic6。1配置好呀。
而且你写得EJB确保在Weblogic上已经正确发布了。
Good Luck!
package product;import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.*;public class Client
{
public static void main(String[] arsgs)
{
private ProductHome home=null;//Home接口
private Product remote = null;//Remote接口 //如果你调用的不是本地上的EJB,则如,url = "t3://192.168.0.88:7001"; 根据你的WebLogic的配置给以变动
String url = "t3://localhost:7001"; try
{
Context ctx=getInitialContext(url); Object ref = ctx.lookup("Product"); home=(ProductHome)PortableRemoteObject.narrow(ref, ProductHome.class); remote = home.create();
}
catch(Exception e)
{
e.printStackTrace();
}
} public Context getInitialContext(String url) throws Exception {
//String url = "t3://192.168.0.88:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e) {
log("Unable to connect to WebLogic server at " + url);
log("Please make sure that the server is running.");
throw e;
}
}
而且你写得EJB确保在Weblogic上已经正确发布了。
Good Luck!
package product;import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.*;public class Client
{
public static void main(String[] arsgs)
{
private ProductHome home=null;//Home接口
private Product remote = null;//Remote接口 //如果你调用的不是本地上的EJB,则如,url = "t3://192.168.0.88:7001"; 根据你的WebLogic的配置给以变动
String url = "t3://localhost:7001"; try
{
Context ctx=getInitialContext(url); Object ref = ctx.lookup("Product"); home=(ProductHome)PortableRemoteObject.narrow(ref, ProductHome.class); remote = home.create();
}
catch(Exception e)
{
e.printStackTrace();
}
} public Context getInitialContext(String url) throws Exception {
//String url = "t3://192.168.0.88:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e) {
log("Unable to connect to WebLogic server at " + url);
log("Please make sure that the server is running.");
throw e;
}
}
解决方案 »
- 求解:sso登陆java项目,但是后面的参数却只解析一个
- struts的jar冲突怎么解决
- struts+spring+hibernate整合问题(unable to proxy method) ---初学
- 关于j2ee中properties文件的问题
- tomcat启动不了,why? 安装oracle之后出现的问题.
- 一个websphere问题
- HttpSession应如何使用?
- 如何在jboss里配置datasource connectionpool 望高手执教 我用的是mysql
- SOS!BMP的findAll()问题.
- 求助:谁能帮我看一下这段代码
- 请问如何在 J2EE SDK 里面使用 SQL Server 数据库?
- 学习J2EE该怎样入手??
jbuilder(5,6)->file->new->enterprise->ejb test client,然后根据向导进行,最后一般在程序中,加上自己调用的函数,比方来个打印什么的,这就是最简单的模式了。
一般来说,很简单,你可以参考上面的程序,刚开始的话,可以什么都不要,加上
try
{
Context ctx=getInitialContext(url); Object ref = ctx.lookup("Product"); home=(ProductHome)PortableRemoteObject.narrow(ref, ProductHome.class); remote接口 remote1 = home.create();
//调用自己的函数,也就是所谓的商业方法。
remote1.自己的函数();
}
就可以了
若是引用别人目录下的文件,则在使用EJB的客户端的Wizards时,有一些问题要注意的。 不过,你把对EJB的错误调用改拉后还不行吗?有什么错误?
Context ctx=new InitialContext();
这一句是通过环境来寻找相对应的Context的.
你换成arke(keke)说的就行了!