wed service客户端在JDK1.7以上无法生成

来源:互联网 发布:旅游网络市场调查 编辑:程序博客网 时间:2024/06/07 01:32
Stack Exchange
Take the 2-minute tour×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

WebService Client Generation Error with JDK8

up vote40 down vote favorite
16

I need to consume a web service in my project. I use NetBeans so I right-clicked on my project and tried to add a new "Web Service Client". Last time I checked, this was the way to create a web service client. But it resulted in an AssertionError, saying:

java.lang.AssertionError: org.xml.sax.SAXParseException; systemId: jar:file:/path/to/glassfish/modules/jaxb-osgi.jar!/com/sun/tools/xjc/reader/xmlschema/bindinfo/binding.xsd; lineNumber: 52; columnNumber: 88; schema_reference: Failed to read schema document 'xjc.xsd', because 'file' access is not allowed due to restriction set by theaccessExternalSchema property.

The default Java platform for NetBeans was JDK8 (Oracle's official version), so when I changed my netbeans.conf file and made JDK7 (from Oracle, as well) as my default, everything worked fine. So I think the problem is with JDK8. Here is myjava -version output:

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

For now, I'm keeping JDK7 as my default Java platform. If there is a way to make JDK8 work please share. Thanks in advance.

shareimprove this question
 
 
I experienced a problem in Eclipse that jaxb sources were not generated when using m2eclipse and jdk1.8. In the markers view I saw a similar error about "accessExternalSchema". When I applied the chosen solution below,restarted eclipse and cleaned the project, the sources got generated! – Jonas Berlin Mar 18 at 10:18

11 Answers

activeoldest votes
up vote88 down vote accepted

Well, I found the solution. (based on http://docs.oracle.com/javase/7/docs/api/javax/xml/XMLConstants.html#ACCESS_EXTERNAL_SCHEMA)

Create a file named jaxp.properties (if it doesn't exist) under /path/to/jdk1.8.0/jre/lib and then write this line in it:

javax.xml.accessExternalSchema = all

That's all. Enjoy JDK 8.

shareimprove this answer
 
 
Just confirming that this worked perfectly for me. – PhilDin Apr 30 '14 at 9:35
 
excellent! I which they made this a little more intuitive – Sebastian Castaldi Jun 4 '14 at 22:25
 
Worked for me but I needed to restart Netbeans for it to work. – AkiraYamamoto Jul 21 '14 at 21:38
 
Tried this. It didn't work for me. Using NetBeans 8.0.2, JRE 1.8.0_25, JDK 1.8.0_25, and Java EE 7. I'm running Windows 7 64bit – Max West Dec 19 '14 at 3:49
 
@Max West, Strange, it worked for me, i got the same configurations as yours except, iam running win 8.1 – bluelabel Feb 2 at 21:42
up vote7 down vote

Not an actual answer but more as a reference.

If you are using the jaxws Maven plugin and you get the same error message, add the mentioned property to the plugin configuration:

...<plugin>  <groupId>org.jvnet.jax-ws-commons</groupId>  <artifactId>jaxws-maven-plugin</artifactId>  <version>2.3</version>  <configuration>    <!-- Needed with JAXP 1.5 -->    <vmArgs>        <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>    </vmArgs>  </configuration></plugin>
shareimprove this answer
 
 
The accessExternalSchema=all value is set by default if you use later versions (like 0.12.3) of theorg.jvnet.jaxb2.maven2:maven-jaxb2-plugin plugin. –  Jon Onstott May 27 at 17:16
up vote5 down vote

I was also getting similar type of error in Eclipse during testing a webservice program on glassfish 4.0 web server:java.lang.AssertionError: org.xml.sax.SAXParseException; systemId: bundle://158.0:1/com/sun/tools/xjc/reader/xmlschema/bindinfo/binding.xsd; lineNumber: 52; columnNumber: 88; schema_reference: Failed to read schema document 'xjc.xsd', because 'bundle' access is not allowed due to restriction set by the accessExternalSchema property.

I have added javax.xml.accessExternalSchema = All in jaxp.properties, but doesnot work for me.

However I found a solution here below which work for me:For GlassFish Server, I need to modify thedomain.xml of the GlassFish, path :<path>/glassfish/domains/domain1 ordomain2/config/domain.xml) and add, <jvm-options>-Djavax.xml.accessExternalSchema=all</jvm-options>under the<java-config> tag

....

<java-config>... <jvm-options>-Djavax.xml.accessExternalSchema=all</jvm-options></java-config>...and then restart the GlassFish server

shareimprove this answer
 
 
I see two instances of <java-config classpath-suffix…> in the domain.xml file. Both have sections of <jvm-options> in them. I placed the line above (with the jvm-options tags) into both sections. It still doesn't work to run the Test Web Service. I know the project is working because the handcoded client file accesses the service files and prints out the right info in the console (from the database associated with the service files). –  Max West Dec 19 '14 at 4:10
 
<p>I did close the project, and the client project, exited NetBeans and waited for Glassfish to shut itself down (it shows a progress meter while it's shutting down). Then, I restarted Netbeans, reloaded the Web Services project, reloaded the Client file (it's just a Java class in a separate/regular Java Project folder). The client prints out the tables, which shows that the server and database server are working, as well as the SOAP service Web Services & EJBs. It's just not working. The accessExternalSchema setting is buried somewhere, and is not getting set properly in the new JDK.</p> – Max West Dec 19 '14 at 4:18
up vote1 down vote

I run ant builds within Eclipse IDE (4.4, Luna, on Windows 7 x64). Rather than modifying the installed JRE lib or any ant scripts (I have multiple projects that include XJC in their builds), I prefer to change Eclipse Settings "External Tools Configurations" and add the following to the VM arguments for the Ant build configuration:

-Djavax.xml.accessExternalSchema=all
shareimprove this answer
 
1 
I use wsdl2java.bat from Apache CXF. So I just inserted the JVM option into this BAT-file. It works. – ka3ak Mar 11 at 9:59
up vote0 down vote

If you are using ant you can add a jvmarg to your java calls:

<jvmarg value="-Djavax.xml.accessExternalSchema=all" />
shareimprove this answer
 
up vote0 down vote

Another solution to address: wiki.netbeans.org

The Web Service Client wizard in the IDE parses the WSDL file when generating a web service client from a web service or WSDL file. You need to modify the IDE configuration file (netbeans.conf) to add the following switch to the netbeans_default_options. You will need to restart the IDE for the change to take effect.

-J-Djavax.xml.accessExternalSchema=all

When deploying to GlassFish you need to enable access to external schema to generate a test client for a web service. To enable access you need to modify the configuration file of the GlassFish Server (GLASSFISH_INSTALL/glassfish/domains/domain1/config/domain.xml) and add the following JVM option element. You will need to restart the server for the change to take effect.

</java-config>  ...  <jvm-options>-Djavax.xml.accessExternalSchema=all</jvm-options></java-config>
shareimprove this answer
 
 
Yeah, did both of those. It doesn't work though. – Max West Dec 19 '14 at 4:20
 
I'm sorry, I can not think anything else. – Referee Apr 8 at 18:59
up vote0 down vote

Another alternative is to update wsimport.sh shell script by adding the following:

The wsimport.sh is located in this directory:

jaxws-ri.2.2.28/bin

exec "$JAVA" $WSIMPORT_OPTS -Djavax.xml.accessExternalSchema=all -jar "$JAXWS_HOME/lib/jaxws-tools.jar" "$@"

shareimprove this answer
 
 
more explanation is welcome – chouaib Nov 11 '14 at 23:55
 
I'd love to try your suggestion, but apparently jaxws-ri.2.2.28/bin is not anywhere on my machine. – Max West Dec 19 '14 at 4:38
up vote0 down vote

Another reference:If you are using the maven-jaxb2-plugin, prior to version 0.9.0, you can use the workaround describedon this issue, in which this behaviour affected the plugin.

shareimprove this answer
 
up vote0 down vote

NetBeans update their tutorial for JDK8 and this Issue:

Getting Started with JAX-WS Web Services -> Enabling Access to External Schema

shareimprove this answer
 
up vote0 down vote

I used it with a regular maven project, and got it solved with this plugin dependency configuration for running thexjc plugin:

     <plugin>        <!-- Needed to run the plugin xjc en Java 8 or superior -->        <groupId>org.codehaus.mojo</groupId>        <artifactId>properties-maven-plugin</artifactId>        <version>1.0-alpha-2</version>        <executions>            <execution>                <id>set-additional-system-properties</id>                <goals>                    <goal>set-system-properties</goal>                </goals>            </execution>        </executions>        <configuration>            <properties>                <property>                    <name>javax.xml.accessExternalSchema</name>                    <value>all</value>                </property>                <property>                    <name>javax.xml.accessExternalDTD</name>                    <value>all</value>                </property>            </properties>        </configuration>    </plugin>
shareimprove this answer
 
up vote0 down vote

thank-you EliuX, it s word I used it with a regular maven project, and got it solved with this plugin dependency configuration for running the xjc plugin:

 <plugin>        <!-- Needed to run the plugin xjc en Java 8 or superior -->        <groupId>org.codehaus.mojo</groupId>        <artifactId>properties-maven-plugin</artifactId>        <version>1.0-alpha-2</version>        <executions>            <execution>                <id>set-additional-system-properties</id>                <goals>                    <goal>set-system-properties</goal>                </goals>            </execution>        </executions>        <configuration>            <properties>                <property>                    <name>javax.xml.accessExternalSchema</name>                    <value>all</value>                </property>                <property>                    <name>javax.xml.accessExternalDTD</name>                    <value>all</value>                </property>            </properties>        </configuration>    </plugin>
shareimprove this answer
 

Your Answer

 

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions taggedwebservice-client java-8 netbeans-8 or ask your own question.

Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load.

0 0
原创粉丝点击