問題の説明
この記事では、D ディスクにインストールされ、システム環境変数のパスが設定されている jdk1.8.0_202 を使用します。
D:\Java\jdk8\bin;D:\Java\jdk8\jre\bin;
この記事での Web サービスの呼び出しの依存関係は次のとおりです。
<!-- webservice调用依赖cxf-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.6</version>
</dependency>
<!-- webservice调用依赖axis-->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-saaj</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
呼び出し方法:
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(wsUrl);
ログエラー:
java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompiler(JAXBUtils.java:711)
at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompilerWithDefaultAllocator(JAXBUtils.java:725)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createSchemaCompiler(DynamicClientFactory.java:423)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:307)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:241)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:234)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:189)
解決プロセス
まず、インターネット上の一般的なソリューションに従い、jdk/lib/tools.jar を jdk と同じレベルの jre/lib にコピーします。
注: tools.jar を表示するには、フォルダーを開いてディレクトリ表示を非表示にする必要があります。
その後、リクエストを再度送信すると、次のようなエラーが発生します。
java.lang.NullPointerException: null
at org.apache.cxf.common.util.Compiler.useJava6Compiler(Compiler.java:187)
at org.apache.cxf.common.util.Compiler.compileFiles(Compiler.java:141)
at org.apache.cxf.common.util.Compiler.compileFiles(Compiler.java:136)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.compileJavaSrc(DynamicClientFactory.java:611)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:370)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:241)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:234)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:189)
パッケージ cxf null ポインター、環境変数の設定を調べたところ、設定はそれぞれ jdk/bin と jdk/jre/bin で、次に tools. null ポインターを直接コピーしました。
インターネットで誰かが言っているのを見たので、dcf.createClient(wsUrl) がクライアントを初期化する前に次のコードを追加しました。
// xxx是当前类的名字
Thread.currentThread().setContextClassLoader(xxx.class.getClassLoader());
まだ null ポインターであることがわかったので、次のように変更しました。
Thread.currentThread().setContextClassLoader(Client.class.getClassLoader());
まだ動かない。
解決
そこで、これをjdk1.8.0_341に置き換え(クリックすると、Quark ネットワーク ディスクを使用してダウンロードできます)、デフォルトのインストール パス (C:\Program Files\Java なので、環境変数を構成する必要はありません) を使用します。
次に、上記の手順を続行し、jdk/lib の下にある tools.jar を、jdk の同じレベルにある jdk/jre/lib と jre/lib にそれぞれコピーします。問題は正常に解決されました。
いいいいいいいいいいいい !!! _ _ _
概要:バージョンの問題に注意し、tools.jar を jre/lib にコピーします。
- apache-cxf-3.2.XX 起動 JDK の最小要件は JDK1.8 です
- apache-cxf-3.1.XX は引き続き JDK1.7 をサポートします