2

Glassfish3.1.2をASとして使用しMaven3を依存関係管理に使用する単純なEJB3.1プロジェクトがあります。ejbプロジェクトのpom.xmlで、generateClientオプションをtrueに設定しました。耳をサーバーに正常にデプロイしてから、単純なスタンドアロンクライアントを作成しようとしました。クライアントのpom.xmlは次のとおりです。

<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>duan</groupId>
   <artifactId>ejb31-app-client</artifactId>
   <version>1.0-SNAPSHOT</version>
   <name>ejb31-app-client</name>
   <description>my app client</description>

<dependencies>
    <dependency>
        <groupId>org.glassfish.main.appclient.client</groupId>
        <artifactId>gf-client-module</artifactId>
        <version>3.1.2</version>
        <type>pom</type>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
            <artifactId>tools</artifactId>
            <groupId>com.sun</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>duan</groupId>
        <artifactId>ejb31</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>ejb-client</type>
    </dependency>
</dependencies>

ここで、ejb31は、クライアントが生成されるejbプロジェクトです。

私のアプリケーションクライアントで使用されているJavaクラスは次のとおりです。

public class Test {
private static HelloWorldBeanRemote helloWorldBean;

public static void main(String[] args) {
    String jndiPath = "java:global/ejb31-ear-1.0/ejb31-ejb/HelloWorldBean";

    try {
        Context ctx = new InitialContext();
        System.out.println("Looking up bean at: " + jndiPath);
        helloWorldBean = (HelloWorldBeanRemote) ctx.lookup(jndiPath);
        System.out.println("Found helloWorldBean:" + helloWorldBean);
        System.out.println("Calling sayHello():");
        String greeting = helloWorldBean.sayHello();
        System.out.println("HelloWorldBean said:" + greeting);
    } catch (NamingException e) {
        System.err.println("Could not find HelloWorldBeanRemote!");
        System.err.println("JNDI path used for lookup:" + jndiPath);
        e.printStackTrace();
    }
}

}

アプリケーションクライアントは、Mavenによって問題なくコンパイルされます。これをEclipseから実行すると、次の例外が発生します。

Caused by: java.lang.ClassNotFoundException: ro.duan.ejb.HelloWorldBeanRemote
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.sun.ejb.EJBUtils.getBusinessIntfClassLoader(EJBUtils.java:688)
    at com.sun.ejb.EJBUtils.loadGeneratedRemoteBusinessClasses(EJBUtils.java:463)
    at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:414)
    ... 7 more

しかし、手動でejb-client.jarをビルドパスに追加すると、チャームのように機能します。したがって、私の結論は、どういうわけかejb-client.jarはコンパイル時に利用可能ですが、実行時には利用できないということです。これを解決する方法について何か考えはありますか?

4

1 に答える 1

0

次の行を削除します。

<scope>compile</scope>

依存範囲の詳細については、http:
//maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scopeを参照してください。

于 2013-03-05T13:33:43.653 に答える