我需要在项目中使用web服务。我使用NetBeans,所以我右键单击我的项目,并尝试添加一个新的“Web服务客户端”。上次我检查时,这是创建web服务客户机的方法。但它导致了一个AssertionError,说:

java.lang.AssertionError: org.xml.sax.SAXParseException;systemId: jar文件:/道路/ / glassfish /模块/ jaxb-osgi.jar ! / com/sun/tools/xjc/reader/xmlschema/bindinfo/binding.xsd;lineNumber: 52个;columnNumber: 88;schema_reference:读取架构文档'xjc失败。由于accessExternalSchema属性设置的限制,不允许访问“文件”。

NetBeans的默认Java平台是JDK8 (Oracle的官方版本),所以当我更改NetBeans .conf文件并将JDK7(也来自Oracle)作为我的默认平台时,一切都工作得很好。所以我认为问题出在JDK8上。这是我的java -version输出:

Java版本“1.8.0” Java(TM) SE运行时环境(build 1.8.0-b132) Java HotSpot(TM) 64位服务器虚拟机(build 25.0-b70,混合模式)

目前,我将JDK7作为默认的Java平台。如果有让JDK8工作的方法,请分享。


当前回答

NetBeans更新了JDK8的教程和以下问题:

JAX-WS Web服务入门->启用对外部模式的访问

其他回答

我在Eclipse IDE (4.4, Luna, Windows 7 x64)中运行蚂蚁构建。与其修改已安装的JRE库或任何ant脚本(我有多个项目,它们的构建中包含XJC),我更喜欢更改Eclipse设置“外部工具配置”,并将以下内容添加到ant构建配置的VM参数中:

-Djavax.xml.accessExternalSchema=all

我在一个常规的maven项目中使用了它,并通过运行xjc插件的插件依赖配置解决了这个问题:

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

下面的代码适用于jdk 1.8.0_66中包含的wsimport 2.2.9:

wsimport -J-Djavax.xml.accessExternalSchema=all ....

在测试glassfish 4.0 web服务器上的web服务程序时,我在Eclipse中也遇到了类似的错误: java.lang.AssertionError: org.xml.sax.SAXParseException;systemId:包:/ / 158.0:1 / com/sun/tools/xjc/reader/xmlschema/bindinfo/binding.xsd;lineNumber: 52个;columnNumber: 88;schema_reference:读取架构文档'xjc失败。由于accessExternalSchema属性设置的限制,'bundle'访问是不允许的。

我已经在jaxp中添加了javax.xml.accessExternalSchema = All。属性,但不为我工作。

然而,我在下面找到了一个适合我的解决方案: 对于GlassFish服务器,我需要修改GlassFish的domain.xml, path:<path>/glassfish/domains/domain1或domain2/config/domain.xml),添加<jvm-options>-Djavax.xml。accessExternalSchema=all</jvm-options>在<java-config>标签下

....

< java-config > ... < jvm选项> -Djavax.xml.accessExternalSchema = < / jvm选项> < / java-config > ...然后重新启动GlassFish服务器

不是一个实际的答案,更多的是作为一个参考。

如果您正在使用jaxws Maven插件,并且得到相同的错误消息,请将上述属性添加到插件配置中:

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