WebService Client Generation Error with JDK8
Asked Answered
I

25

249

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.

Inflame answered 11/4, 2014 at 11:39 Comment(1)
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!Gamone
I
432

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.

Inflame answered 11/4, 2014 at 12:36 Comment(19)
Worked for me but I needed to restart Netbeans for it to work.Sirius
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 64bitChrystal
@Max West, Strange, it worked for me, i got the same configurations as yours except, iam running win 8.1Mesic
Works for intelliJ too.Miffy
I also had the same issue as Max West, but followed the answer provided by @Debashish Barik and it now works fine for meLovegrass
Works as advertised just confirmed. Some platform details: maven = 3.3.1 JDK = 1.8.0_40 OS = OSX 10.10.3Bullroarer
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?Peek
@DannyLo because java 7 is reaching end-of-life soon, that's why... ;)Gonsalez
Thanks a TON! This works for Java 1.8 but not for 1.7.Delatorre
This worked for me, but I had to put the file under /path/to/jdk1.8.0/lib not under the further jre directory.Nonagenarian
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.Bonaire
Thanks bro.It worked like a charm...thanks a lot for sharing it :)Eichler
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");Grecoroman
@Bonaire Agreed, see my answer for a portable solution that does not require JDK modification or global JDK flagsPilloff
Is there a way to set this property in another place, if the JDK folder is read-only due to company policy ?Kruse
@SorinPostelnicu this jvm configuration can also be done in the pom.xmlTraject
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.Inorganic
works as explained here. Also had a JDK8, for an older project!Leilanileininger
Why isn't this the default behavior? Why block access to https by default?Basel
G
132

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>
Grot answered 17/3, 2015 at 11:20 Comment(3)
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.Retrochoir
The above didn't work for me. This version did: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>${version.jaxws.plugin}</version> <configuration> <!-- Needed with JAXP 1.5 --> <vmArgs> <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> </vmArgs> </configuration> </plugin>Ensphere
@JonOnstott: have the latest 2.4.1 and it's not working by default. Had to add this like in the answer.Felicefelicia
N
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
Natterjack answered 15/7, 2014 at 2:43 Comment(3)
I use wsdl2java.bat from Apache CXF. So I just inserted the JVM option into this BAT-file. It works.Simonton
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)Heliostat
I had a similar issue when I tried to run mvn clean install , I just added this above flag and it was succesfully deployed. ThanksSelie
D
40

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

wsimport -J-Djavax.xml.accessExternalSchema=all ....
Doge answered 22/12, 2015 at 22:31 Comment(2)
This works for me. I tried with jdk 1.8.0_65 and that didn't work, so make sure you are using jdk 1.8.0_66 or later.Byandby
This is the correct answer when using wsimport directly.Anorthic
P
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.

Predisposition answered 28/1, 2016 at 19:14 Comment(1)
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!Lyndes
E
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>
Erect answered 27/2, 2016 at 16:51 Comment(1)
Perhaps it is the vmArgs -Djavax.xml.accessExternalSchema=all that is configured in your plugin declaration. It is discussed in Netbeans Bug 244891Piscine
F
17

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"]
    }
}
Fincher answered 7/4, 2016 at 13:29 Comment(0)
N
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>
Novikoff answered 20/11, 2015 at 19:32 Comment(1)
thanks! all the above options do not help and yours is working for meTyrothricin
M
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

Meddle answered 21/6, 2014 at 17:37 Comment(2)
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).Chrystal
<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>Chrystal
C
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>
Copyedit answered 10/10, 2017 at 18:37 Comment(0)
I
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
Indigestion answered 4/11, 2019 at 8:48 Comment(1)
On MacOS: Create the file jaxp.properties under /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/libNatatorial
G
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

Gerlach answered 15/1, 2016 at 20:42 Comment(2)
Works with Linux Mint 17.3, JDK 1.8.0.74 and Intellij IDEA 15. Thx.Wean
Nice ! it's also work for me when I use "mvn clean install -Djavax.xml.accessExternalSchema=all" directly on terminal independently of IDEKamerun
L
6

This works on jdk1.8.0_65

wsimport -J-Djavax.xml.accessExternalSchema=all -keep -verbose https://your webservice url?wsdl
Lure answered 25/11, 2016 at 8:10 Comment(0)
K
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>
Kester answered 9/12, 2016 at 14:0 Comment(0)
A
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>
Alligator answered 21/7, 2017 at 17:45 Comment(0)
E
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>
Endways answered 16/7, 2015 at 15:30 Comment(1)
With this solution, I needed to update jaxws-maven-plugin to 2.5 as specified in others answers mojohaus.org/jaxws-maven-plugin/usage.html But still, best answer in my case, thank you!Carissacarita
S
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>
Scurrility answered 23/7, 2014 at 14:45 Comment(1)
I'm sorry, I can not think anything else.Gissing
R
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.

Resent answered 19/4, 2019 at 18:49 Comment(0)
A
1

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

<jvmarg value="-Djavax.xml.accessExternalSchema=all" />
Abuttals answered 27/6, 2014 at 20:17 Comment(1)
Can you be more specific where you put this in an ant file?Ambience
E
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" "$@"

Expository answered 11/11, 2014 at 23:52 Comment(1)
I'd love to try your suggestion, but apparently jaxws-ri.2.2.28/bin is not anywhere on my machine.Chrystal
J
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.

Josefjosefa answered 25/6, 2015 at 14:22 Comment(0)
O
0

NetBeans update their tutorial for JDK8 and this Issue:

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

Orlov answered 15/7, 2015 at 17:43 Comment(0)
B
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).

Bee answered 7/7, 2017 at 19:25 Comment(0)
W
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

Witmer answered 23/8, 2022 at 8:1 Comment(0)
L
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.

Lawerencelawes answered 14/12, 2022 at 9:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.