246

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.

a.b
  • 9,414
  • 5
  • 26
  • 22
  • 2
    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 '15 at 10:18

25 Answers25

430

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.

a.b
  • 9,414
  • 5
  • 26
  • 22
  • Worked for me but I needed to restart Netbeans for it to work. – Akira Yamamoto 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 03:49
  • @Max West, Strange, it worked for me, i got the same configurations as yours except, iam running win 8.1 – bluelabel Feb 02 '15 at 21:42
  • 15
    Works for intelliJ too. – Mafro34 Feb 17 '15 at 10:28
  • I also had the same issue as Max West, but followed the answer provided by @Debashish Barik and it now works fine for me – Matt Williams Mar 04 '15 at 18:12
  • Works as advertised just confirmed. Some platform details: maven = 3.3.1 JDK = 1.8.0_40 OS = OSX 10.10.3 – wojtek_z May 13 '15 at 15:05
  • 1
    I can confirm this solution also as working for maven build in eclipse with maven and jaxb-plugin. Can somebody explain why you don't need this property for Java7? – Danny Lo May 20 '15 at 09:33
  • @DannyLo because java 7 is reaching end-of-life soon, that's why... ;) – vikingsteve May 21 '15 at 11:52
  • 1
    Thanks a TON! This works for Java 1.8 but not for 1.7. – Stark07 Jan 15 '16 at 05:03
  • 3
    This worked for me, but I had to put the file under `/path/to/jdk1.8.0/lib` not under the further `jre` directory. – Zefira Mar 17 '16 at 20:27
  • 25
    This isn't very portable. You would need to tweak a local JDK installation on a machine of every developer that tries to build the project. – Natix Jun 15 '16 at 11:43
  • Thanks bro.It worked like a charm...thanks a lot for sharing it :) – Thomas Jul 12 '16 at 13:16
  • 8
    this is not working for me, the following worked: javax.xml.accessExternalDTD = all, Also I can set this in code and it works: System.setProperty("javax.xml.accessExternalDTD", "all"); – qartal Jul 19 '16 at 18:56
  • @Natix Agreed, see my answer for a portable solution that does not require JDK modification or global JDK flags – Dave B Sep 28 '16 at 16:46
  • Is there a way to set this property in another place, if the JDK folder is read-only due to company policy ? – Sorin Postelnicu Oct 26 '17 at 16:53
  • @SorinPostelnicu this jvm configuration can also be done in the pom.xml – bbaassssiiee Jan 19 '19 at 20:28
  • Does this get added to the jenkins or nexus instance? I created the file in both and added mentioned property with no success. Here is my error. `Nexus Repository Manager 3.x connection failed javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 123; External DTD: Failed to read external DTD 'xhtml1-transitional.dtd', because 'http' access is not allowed due to restriction set by the accessExternalDTD property.]` Any help is tremendously appreciated. – Mihado Sep 12 '20 at 03:19
  • works as explained here. Also had a JDK8, for an older project! – Jaja Aug 04 '21 at 14:22
  • Why isn't this the default behavior? Why block access to https by default? – Jesse Barnum Mar 24 '23 at 04:45
128

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>
jassuncao
  • 4,695
  • 3
  • 30
  • 35
  • 4
    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 '15 at 17:16
  • 1
    The above didn't work for me. This version did: org.codehaus.mojo jaxws-maven-plugin ${version.jaxws.plugin} -Djavax.xml.accessExternalSchema=all – Dr4gon Oct 04 '16 at 15:11
  • @JonOnstott: have the latest 2.4.1 and it's not working by default. Had to add this like in the answer. – Robert Niestroj May 31 '17 at 08:02
42

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
gb96
  • 1,674
  • 1
  • 18
  • 26
  • 2
    I use wsdl2java.bat from Apache CXF. So I just inserted the JVM option into this BAT-file. It works. – ka3ak Mar 11 '15 at 09:59
  • 1
    I could also add, than if we include this option as ant parameter, all other includes mentioned here, are excessive. But not vice versa! So this is the best solution. +1 (of course, Maven users should do appropriate change in Maven options) – Gangnus Dec 14 '15 at 14:28
  • 2
    I had a similar issue when I tried to run mvn clean install , I just added this above flag and it was succesfully deployed. Thanks – Spear A1 Apr 18 '19 at 20:18
39

The following works for wsimport 2.2.9 included in jdk 1.8.0_66:

wsimport -J-Djavax.xml.accessExternalSchema=all ....
tanderson
  • 1,169
  • 12
  • 29
26

In my case adding:

javax.xml.accessExternalSchema = all

to jaxp.properties didn't work, I've to add:

javax.xml.accessExternalDTD = all

My environment is linux mint 17 and java 8 oracle. I'll put it there as an answer for people with the same problem.

moretti.fabio
  • 1,128
  • 13
  • 32
  • 2
    It depends whether you want to allow access to external DTD or to XML Schema (XSD). DTD is the predecessor of XML Schema. There might also be cases where you need to set both! – Philip Helger May 05 '17 at 07:39
17

I tested this for version 2.4 of artifact org.codehaus.mojo and that worked ~

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
            <execution>

                <goals>
                    <goal>wsimport</goal>
                </goals>
                <configuration>
                    <wsdlDirectory>path/to/dir/wsdl</wsdlDirectory>
                </configuration>
                <id>wsimport-web-service</id>
                <phase>generate-sources</phase>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>javax.xml</groupId>
                <artifactId>webservices-api</artifactId>
                <version>${webservices-api-version}</version>
            </dependency>
        </dependencies>
        <configuration>
            <vmArgs>
                <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
            </vmArgs>
            <sourceDestDir>generated-sources/jaxws-wsimport</sourceDestDir>
            <xnocompile>true</xnocompile>
            <verbose>true</verbose>
            <extension>true</extension>
            <sei>/</sei>
        </configuration>
    </plugin>
</plugins>
Mehdi
  • 3,795
  • 3
  • 36
  • 65
  • 1
    Perhaps it is the vmArgs `-Djavax.xml.accessExternalSchema=all` that is configured in your plugin declaration. It is discussed in Netbeans [Bug 244891](https://netbeans.org/bugzilla/show_bug.cgi?id=244891) – kosgeinsky Mar 21 '16 at 10:03
16

Here is a hint Hint for gradle users without admin rights: add this line to your jaxb-task:

System.setProperty('javax.xml.accessExternalSchema', 'all')

it will look like this:

jaxb {
    System.setProperty('javax.xml.accessExternalSchema', 'all')
    xsdDir = "${project.name}/xsd"
    xjc {
        taskClassname = "com.sun.tools.xjc.XJCTask"
        args = ["-npa", "-no-header"]
    }
}
Java_Waldi
  • 924
  • 2
  • 12
  • 29
13

If you are getting this problem when converting wsdl to jave with the cxf-codegen-plugin, then you can solve it by configuring the plugin to fork and provide the additional "-Djavax.xml.accessExternalSchema=all" JVM option.

        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>${cxf.version}</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <fork>always</fork>
                        <additionalJvmArgs>
                            -Djavax.xml.accessExternalSchema=all
                        </additionalJvmArgs>
pjklauser
  • 1,156
  • 11
  • 13
10

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

Sled
  • 18,541
  • 27
  • 119
  • 168
Debashish
  • 101
  • 1
  • 4
  • I see two instances of in the domain.xml file. Both have sections of 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 04:10
  • 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. – Max West Dec 19 '14 at 04:18
9

Enabling Access to External Schema

You need to enable the IDE and the GlassFish Server to access external schema to parse the WSDL file of the web service. To enable access you need to modify the configuration files of the IDE and the GlassFish Server. For more details, see the FAQ How to enable parsing of WSDL with an external schema? Configuring the IDE

To generate a web service client in the IDE from a web service or WSDL file you need to modify the IDE configuration file (netbeans.conf) to add the following switch to netbeans_default_options.

-J-Djavax.xml.accessExternalSchema=all

For more about locating and modifying the netbeans.conf configuration file, see Netbeans Conf FAQ. Configuring the GlassFish Server

If you are deploying to the GlassFish Server you need to modify the configuration file of the GlassFish Server (domain.xml) to enable the server to access external schemas to parse the wsdl file and generate the test client. To enable access to external schemas, open the GlassFish configuration file (GLASSFISH_INSTALL/glassfish/domains/domain1/config/domain.xml) and add the following JVM option element (in bold). 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>
Ashwin Patil
  • 1,307
  • 1
  • 23
  • 27
7

Create a file named jaxp.properties (if it doesn’t exist) under path to your "JDK version/jre/lib" and then add the following line in it.

javax.xml.accessExternalSchema = all
Gayan Mettananda
  • 1,498
  • 14
  • 21
  • On MacOS: Create the file `jaxp.properties` under `/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib` – ederrafo Nov 28 '20 at 02:55
6

When using Maven with IntelliJ IDE you can add -Djavax.xml.accessExternalSchema=all to Maven setting under JVM Options for Maven Build Tools Runner configuration

Dexter Legaspi
  • 3,192
  • 1
  • 35
  • 26
  • Works with Linux Mint 17.3, JDK 1.8.0.74 and Intellij IDEA 15. Thx. – stuchl4n3k Mar 16 '16 at 14:50
  • Nice ! it's also work for me when I use "mvn clean install -Djavax.xml.accessExternalSchema=all" directly on terminal independently of IDE – Tanorix Aug 05 '16 at 09:14
6

This works on jdk1.8.0_65

wsimport -J-Djavax.xml.accessExternalSchema=all -keep -verbose https://your webservice url?wsdl
Stephen
  • 169
  • 4
  • 10
4

For those using the ANT task wsimport, a way of passing the option as suggested by @CMFly and specified in the documentation is the following:

<wsimport
   <!-- ... -->
   fork="true"
  >
  <jvmarg value="-Djavax.xml.accessExternalSchema=all"/>
</wsimport>
Daniele Piccioni
  • 503
  • 6
  • 12
4

It is now fixed in 2.5 version (released in jul/17). https://github.com/mojohaus/jaxws-maven-plugin/issues/8.

For the 2.4.x versions there is a workaround (as decribed in https://github.com/mojohaus/jaxws-maven-plugin/issues/4):

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.4.1</version>
        <dependencies>
            <dependency>
                <groupId>com.sun.xml.ws</groupId>
                <artifactId>jaxws-tools</artifactId>
                <version>2.2.10</version>
            </dependency>
        </dependencies>
    </plugin>
Douglas Gardim
  • 420
  • 1
  • 4
  • 11
3

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>
EliuX
  • 11,389
  • 6
  • 45
  • 40
  • With this solution, I needed to update `jaxws-maven-plugin` to 2.5 as specified in others answers https://www.mojohaus.org/jaxws-maven-plugin/usage.html But still, **best answer** in my case, thank you! – DependencyHell Dec 09 '19 at 11:57
2

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>
2

I have just tried that if you use SoapUI (5.4.x) and use Apache CXF tool to generate java code, put javax.xml.accessExternalSchema = all in YOUR_JDK/jre/lib/jaxp.properties file also works.

rinold simon
  • 2,782
  • 4
  • 20
  • 39
TGU
  • 181
  • 2
  • 7
1

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

<jvmarg value="-Djavax.xml.accessExternalSchema=all" />
CMfly
  • 103
  • 5
0

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

0

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.

Niel de Wet
  • 7,806
  • 9
  • 63
  • 100
0

NetBeans update their tutorial for JDK8 and this Issue:

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

user3158918
  • 121
  • 1
  • 5
0

A very simple portable solution would be, to place the following line of code somewhere in a crucial part of your code, a part of which you are sure that it will be run (for example right in the main method):

System.setProperty("javax.xml.accessExternalDTD", "all");

This sets the needed system property programmatically, without having to do tricky maven pom.xml changes (which for some reason didn't work for me).

R Hoekstra
  • 99
  • 3
0

If you are using Intellij IDEA, in the maven tool window

enter image description here

select Maven Settings and expand the Maven drop down and select Runner.

enter image description here

Under the VM Options add -Djavax.xml.accessExternalSchema=all

Kihats
  • 3,326
  • 5
  • 31
  • 46
0

Using RAD 9.6 with JDK 1.8 websphere 8.5 runtime on Windows, editing the xjc.bat as in Generate Java gives "Failed to read external schema..." error didn't work with me, adding/updating the jaxb.properties didn't work as well,

however I edited the wsimport as in below note

you may modify the wsimport.bat file to specify the property directly as one of the jvm arguments like below:-Djavax.xml.accessExternalSchema=all Our customers reported that the above solution worked for them.

as mentioned in SAXParseException, and it was the solution in my case.

Reema
  • 70
  • 4