0

私はHead First EJBに従っています。EJB 2.0 が含まれていることは知っていますが、これは現在 EJB 3.1 が含まれているため古いものです。しかし、Head first book は、私たちのようなアマチュアにとって学習に適した本だと考えています。

J2ee 1.3.1 RI と jdk 1.4 を使用しています。「デプロイ」ツールを実行して EJB でデプロイしたところ、以下に示す ejb クライアント JAVA プログラムが作成されました。

import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

import java.util.*;

public class AdviceClient {
    public static void main(String[] args){
        new AdviceClient().go();
    }

    public void go(){
        try{

            Properties props=new Properties();
            props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
            //props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
            //env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
            //props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sun.enterprise.naming.SerialInitContextFactory");
            props.setProperty(Context.PROVIDER_URL,"rmi://localhost:1050"); 
            //props.setProperty("java.naming.provider.url","rmi://localhost:1099");

            Context ic = new InitialContext(props);
            Object o = ic.lookup("Advisor");

            AdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o,AdviceHome.class);

            Advice advisor = home.create();
            System.out.println(advisor.getAdvice());
        }
        catch(Exception ex){
            ex.printStackTrace();
        }
    }
}






Following the book, I compiled the program. The "Properties" part is something not mentioned in the example. I got it from some other examples on the web. Now, that when I am executing the client, am getting the following error:


F:\EJBProject\advice>java -classpath AdviceAppClient.jar;. AdviceClient
javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:

        java.net.SocketTimeoutException: Read timed out]
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(Unknown Source)
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(Unknown Source)
        at javax.naming.InitialContext.lookup(Unknown Source)
        at AdviceClient.go(AdviceClient.java:26)
        at AdviceClient.main(AdviceClient.java:11)
Caused by: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
        java.net.SocketTimeoutException: Read timed out
        at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
        at sun.rmi.server.UnicastRef.newCall(Unknown Source)
        at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
        ... 5 more
Caused by: java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.io.BufferedInputStream.fill(Unknown Source)
        at java.io.BufferedInputStream.read(Unknown Source)
        at java.io.DataInputStream.readByte(Unknown Source)

助けてください。私はここでひどく立ち往生しています。OCBCD試験を受けたかった!

よろしく、Shouvanik

4

1 に答える 1

0

最後に解決しました。

最初の EJB サンプルの実行中に問題が発生した場合は、次の手順に従って、HeadFirst EJB の最初のサンプルを実行してください。

ソフトウェア 1. j2sdk1.4.1 - jdk 2. j2sdkee1.3.1 - j2ee RI 3. CMD (コマンド プロンプト)

c:\j2sdkee1.3.1\lib\j2ee.jar ライブラリを使用してすべてのクラスをコンパイルします。ここで、アプリケーションを作成し、RI 内に EJB をデプロイします。本に示されているように、アプリケーション クライアントをダウンロードします。

さて、トリッキーな部分です。

次の jar を使用してクライアント クラスをコンパイルします。

javac -classpath AdviceAppClient.jar;c:\j2sdkee1.3.1\lib\j2ee.jar AdviceClient.java

次に、次のようにクライアントを実行します

java -cp AdviceAppClient.jar;c:\j2sdkee1.3.1\lib\j2ee.jar;c:\j2sdk1.4.1\jre\lib\rt.jar;. アドバイスクライアント

于 2013-05-06T09:09:30.180 に答える