我需要在项目中使用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工作的方法,请分享。


当前回答

我刚刚尝试过,如果您使用SoapUI (5.4.x)并使用Apache CXF工具生成java代码,请将javax.xml.accessExternalSchema = all放在YOUR_JDK/jre/lib/jaxp中。属性文件也可以工作。

其他回答

对于没有管理员权限的gradle用户,这里有一个提示:将这一行添加到你的jaxb-task中:

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

它看起来是这样的:

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

下面的代码适用于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服务器

另一个替代方案是通过添加以下内容更新wsimport.sh shell脚本:

wsimport.sh位于这个目录下:

jaxws-ri.2.2.28 / bin

执行“$JAVA”$WSIMPORT_OPTS -Djavax.xml。accessExternalSchema=all -jar "$JAXWS_HOME/lib/jaxws-tools.jar" "$@"

我在一个常规的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>