EJB 内で JAX-RS クライアントを作成しているときに、JAX-RS の実装を取得できない理由がわかりません。Glassfish 3.1 のようなアプリケーション サーバーは、Jersey のような JAX-RS 実装を提供する必要があると想定されており、依存関係のように追加する必要はありませんが、それを見つけることができません。
エラーは、java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
Glassfish が提供する必要があるため、Jersey をクラスパスに追加する必要はないと思います。
エラーを生成するコードは
Client client = ClientBuilder.newClient();
このコードは EJB メソッド内にあり、私のテスト ケースは次のとおりです。
EJBContainer container = EJBContainer.createEJBContainer();
MyService service = (MyService) container.getContext().lookup("java:global/classes/MyService");
service.create(null);
pom.xml ファイルの依存関係は次のようになります。
<dependencies>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.7</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
パッケージはWARファイルですが、問題ないと思います。