EJB 部署及應用
我編寫了一個EJB 如下:
部署成功,但在執行時出現錯誤。
請各位高手不吝賜教,不勝感激!!!
執行環境、程式碼、命令和錯誤資訊全部列在下面
RemoteInterface.java
/**
* 第一步:
*
定義一個新的介面繼承javax.ejb.EJBObject。新定義的介面中的每一個方法都必須丟擲
* java.rmi.RemoteException異常。
*/
public interface RemoteInterface extends
javax.ejb.EJBObject
{
public String message(String str)throws
java.rmi.RemoteException;
}
RemoteObject.java
/**
* 第二步:
*
定義一個類來實現javax.ejb.SessionBean介面。並在該類中實現在第一步中編寫的介面中所定義的方法。
*/
public class RemoteObject implements
javax.ejb.SessionBean
{
public String message(String str)throws
java.rmi.RemoteException
{
System.out.println("Remote Object Received From
Client: \""+str+"\"");
//列印(從客戶端)接收到的字串。
return "Hello,I'm Remote Object,I received your
message: \'"+str+"\'"; //返回一應答字串。
}
public RemoteObject() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(javax.ejb.SessionContext
sc) {}
}
RemoteHome.java
/**
* 第三步:
* 定義一個類繼承javax.ejb.EJBHome 。
*/
public interface RemoteHome extends javax.ejb.EJBHome
{
RemoteInterface create()throws
java.rmi.RemoteException,javax.ejb.CreateException;
}
//: 第四步 Client.java
public class Client {
public static void main(String[] args){
try{
javax.naming.Context initContext=new javax.naming.InitialContext();
//遠端查詢,由名字得到對應的物件。
Object obj=initContext.lookup("HelloWorld");
RemoteHome home=(RemoteHome)javax.rmi.PortableRemoteObject.narrow(obj,RemoteHome.class);
RemoteInterface remote=home.create();
//遠端方法呼叫
String receiveFromRemote=remote.message("Hello,Remote Object!");
System.out.println("Client Received From Remote Object: \""+receiveFromRemote+"\"");
} catch(Exception e) {
e.printStackTrace();
}
}
}
//:Deployment Descriptor: ejb-jar.xml
<?xml version='1.0' encoding='UTF-8'?> <ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" > <display-name xml:lang="zh" >HelloWorld</display-name> <enterprise-beans> <session> <ejb-name>RemoteObject</ejb-name> <home>RemoteHome</home> <remote>RemoteInterface</remote> <ejb-class>RemoteObject</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> <ejb-ref> <ejb-ref-name>HelloWorld</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>RemoteHome</home> <remote>RemoteInterface</remote> </ejb-ref> <security-identity> <use-caller-identity> </use-caller-identity> </security-identity> </session> </enterprise-beans> </ejb-jar>
執行環境:
indows XP Professional
Sun MicroSystem j2ee 1.4
Deployment Tool for Java 3 Platform Enterprise Edition 1.4
部署成功!
發出命令:
D:\HelloWorld>java -classpath c:\sun\appserver\lib\j2ee.jar;c:\sun\appserver\lib;.;HelloWorldClient.jar; Client
錯誤資訊:
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at Client.main(Client.java:12)
D:\HelloWorld>
部署成功,但在執行時出現錯誤。
請各位高手不吝賜教,不勝感激!!!
執行環境、程式碼、命令和錯誤資訊全部列在下面
RemoteInterface.java
/**
* 第一步:
*
定義一個新的介面繼承javax.ejb.EJBObject。新定義的介面中的每一個方法都必須丟擲
* java.rmi.RemoteException異常。
*/
public interface RemoteInterface extends
javax.ejb.EJBObject
{
public String message(String str)throws
java.rmi.RemoteException;
}
RemoteObject.java
/**
* 第二步:
*
定義一個類來實現javax.ejb.SessionBean介面。並在該類中實現在第一步中編寫的介面中所定義的方法。
*/
public class RemoteObject implements
javax.ejb.SessionBean
{
public String message(String str)throws
java.rmi.RemoteException
{
System.out.println("Remote Object Received From
Client: \""+str+"\"");
//列印(從客戶端)接收到的字串。
return "Hello,I'm Remote Object,I received your
message: \'"+str+"\'"; //返回一應答字串。
}
public RemoteObject() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(javax.ejb.SessionContext
sc) {}
}
RemoteHome.java
/**
* 第三步:
* 定義一個類繼承javax.ejb.EJBHome 。
*/
public interface RemoteHome extends javax.ejb.EJBHome
{
RemoteInterface create()throws
java.rmi.RemoteException,javax.ejb.CreateException;
}
//: 第四步 Client.java
public class Client {
public static void main(String[] args){
try{
javax.naming.Context initContext=new javax.naming.InitialContext();
//遠端查詢,由名字得到對應的物件。
Object obj=initContext.lookup("HelloWorld");
RemoteHome home=(RemoteHome)javax.rmi.PortableRemoteObject.narrow(obj,RemoteHome.class);
RemoteInterface remote=home.create();
//遠端方法呼叫
String receiveFromRemote=remote.message("Hello,Remote Object!");
System.out.println("Client Received From Remote Object: \""+receiveFromRemote+"\"");
} catch(Exception e) {
e.printStackTrace();
}
}
}
//:Deployment Descriptor: ejb-jar.xml
<?xml version='1.0' encoding='UTF-8'?> <ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" > <display-name xml:lang="zh" >HelloWorld</display-name> <enterprise-beans> <session> <ejb-name>RemoteObject</ejb-name> <home>RemoteHome</home> <remote>RemoteInterface</remote> <ejb-class>RemoteObject</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> <ejb-ref> <ejb-ref-name>HelloWorld</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>RemoteHome</home> <remote>RemoteInterface</remote> </ejb-ref> <security-identity> <use-caller-identity> </use-caller-identity> </security-identity> </session> </enterprise-beans> </ejb-jar>
執行環境:
indows XP Professional
Sun MicroSystem j2ee 1.4
Deployment Tool for Java 3 Platform Enterprise Edition 1.4
部署成功!
發出命令:
D:\HelloWorld>java -classpath c:\sun\appserver\lib\j2ee.jar;c:\sun\appserver\lib;.;HelloWorldClient.jar; Client
錯誤資訊:
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at Client.main(Client.java:12)
D:\HelloWorld>
// 在此輸入java程式碼 <p class="indent"> |
相關文章
- LNMP部署及應用LNMP
- LAMP平臺部署及應用(一)LAMP
- 01 . SaltStack部署配置及簡單應用
- 【轉】Docker部署Tomcat及Web應用DockerTomcatWeb
- 01 . ELK Stack簡介原理及部署應用
- OCR表單識別SDK的部署及應用
- LAMP平臺服務簡介、部署及應用LAMP
- Istio實踐(1)-環境搭建及應用部署
- 在tomcat中部署的應用不能訪問weblogic上部署的ejbTomcatWeb
- 將EJB 3應用程式遷移到GlassFish
- RMI應用部署
- 10分鐘內一鍵部署環境及應用
- Terraform部署容器服務Swarm叢集及WordPress應用ORMSwarm
- 輕鬆部署 Laravel 應用 | 《08. 手動部署 - 部署應用程式碼》Laravel
- 不使用EJB如何做分散式應用?分散式
- EJB 中的session facade模式應用Session模式
- vcenter6.7生產環境叢集部署及應用
- Docker部署Angular應用DockerAngular
- Flask 應用如何部署Flask
- 用 Jenkins 部署 PHP 應用JenkinsPHP
- puppet完全攻略(一)puppet應用原理及安裝部署
- web應用跨容器呼叫EJB的異常問題Web
- MyEclipse下EJB應用程式的開發Step By StepEclipse
- 阿里canal部署和應用阿里
- 使用 Docker 部署 Node 應用Docker
- Docker常用的應用部署Docker
- nginx + uWSGI + flask應用部署NginxFlask
- 快速應用部署的方法
- SQLCoder部署和應用SQL
- golang: 線上上用nginx部署應用GolangNginx
- Websphere安裝、企業部署應用 【應用案例】Web
- Web應用防火牆是什麼?談談原理及部署建議Web防火牆
- ubuntu20安裝docker、redis、mysql及部署net6應用UbuntuDockerRedisMySql
- iOS應用架構談(4):本地持久化方案及動態部署iOS應用架構持久化
- Jboss7 部署EJB3 簡明教程
- 用 Ansible 部署無服務應用!
- 用JavaFX構建部署Android應用JavaAndroid
- 將Laravel應用部署到HerokuLaravel