启动jboss
从cmd中到jboss的bin目录下,run -c all启动jboss
文件打包(发布)的目录{jbosshome}/server/all/deploy/JbossTest.jar
在EJB工程中加入{jbosshome}/client/jbossall-client.jar(很重要)
下面是两个EJB类和一个测试类
远程接口
import javax.ejb.Remote;
@Remote
public interface TestRemote {
public String say();
}
无状态会话bean
import javax.ejb.Stateless;
@Stateless
public class Test implements TestRemote {
public String say() {
return "say hello";
}
}
测试类
import java.util.Properties;
import javax.naming.InitialContext;
public class TestEjb {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url","localhost:1099");
props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming");
try {
InitialContext ct = new InitialContext(props);
TestRemote test = (TestRemote)ct.lookup("Test/remote");
System.out.println(test.say());
} catch (Exception e) {
e.printStackTrace();
}
}
}
weblogic加入包{weblogichome}/wlserver_10.0/server/lib/weblogic.jar
weblogic10中用
String url = "t3://127.0.0.1:7001";
String factory = "weblogic.jndi.WLInitialContextFactory";
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, factory);
props.setProperty(Context.PROVIDER_URL, url);
运行到TestRemote test = (TestRemote)ct.lookup("Test/remote");就报错,不知道如何改!!希望有高人可以指点!