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

Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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 the accessExternalSchema 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 my java -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.

share improve 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

up vote 88 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.

share improve 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

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>
share improve this answer
 
 
The accessExternalSchema=all value is set by default if you use later versions (like 0.12.3) of the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin plugin. –  Jon Onstott May 27 at 17:16

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 the domain.xml of the GlassFish, path :<path>/glassfish/domains/domain1 or domain2/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

share improve 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

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
share improve 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

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

<jvmarg value="-Djavax.xml.accessExternalSchema=all" />
share improve this answer
 

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>
share improve 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

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" "$@"

share improve 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

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

share improve this answer
 

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>
share improve this answer
 

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>
share improve this answer
 

Your Answer

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值