如何为 JAXB2 Maven 插件指定 javax.xml.accessExternalSchema

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26344590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:18:18  来源:igfitidea点击:

How to specify javax.xml.accessExternalSchema for the JAXB2 Maven plugin

javamavenmaven-jaxb2-plugin

提问by Josh

I have a maven plugin (jaxb2) and I need to supply a jvm arg to it. I don't think there is a tag to add jvm args in the pom for it.

我有一个 Maven 插件(jaxb2),我需要为它提供一个 jvm arg。我不认为有一个标签可以在 pom 中为它添加 jvm args。

I know I can pass in jvm args on the command line eg: mvn clean install -Djavax.xml.accessExternalSchema=all

我知道我可以在命令行上传递 jvm args 例如: mvn clean install -Djavax.xml.accessExternalSchema=all

Is it possible to set this jvm arg in the pom so that I don't have to type it into the command line every time?

是否可以在 pom 中设置这个 jvm arg,这样我就不必每次都在命令行中输入它?

(As aside - this jvm arg is required in order for it to work with JAVA-8. It works fine with JAVA-7)

(顺便说一句 - 这个 jvm arg 是必需的,以便它与 JAVA-8 一起工作。它与 JAVA-7 一起工作正常)

采纳答案by lexicore

This is relevant to the new XML security properties in JAXB 1.5, introduced in Java 8. This is why your builds now fail on Java 8 but work with Java 7.

这与Java 8 中引入的JAXB 1.5 中的新XML 安全属性相关。这就是您的构建现在在 Java 8 上失败但可以在 Java 7 上工作的原因。

If you're using my maven-jaxb2-plugin, please upgrade to the version 0.9.0or later (current is 0.10.0). It has now a accessExternalSchemaswitch (default is all).

如果您使用的是 my maven-jaxb2-plugin,请升级到 版本0.9.0或更高版本(当前为0.10.0)。它现在有一个accessExternalSchema开关(默认为all)。

This sets precisely javax.xml.accessExternalSchema=all.

这正好设置javax.xml.accessExternalSchema=all

Please see the documentation.

请参阅文档

回答by creechy

Take a look at the Maven Compiler Plugin. Specifically you should be able to use the <compilerArgument>element to pass settings to the compiler.

查看 Maven 编译器插件。具体来说,您应该能够使用该<compilerArgument>元素将设置传递给编译器。

See http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.htmlfor examples.

有关示例,请参阅http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html

回答by bmargulies

If you are trying to change the behavior of the JVM that is running Maven itself, add options to MAVEN_OPTS in the environment before launching mvn.

如果您尝试更改运行 Maven 本身的 JVM 的行为,请在启动 mvn 之前向环境中的 MAVEN_OPTS 添加选项。

回答by Amit Misra

I came across this issue while working with jaxb2-maven-plugin. I found a related jira issue for maven-jabx2-plugin - https://java.net/projects/maven-jaxb2-plugin/lists/issues/archive/2014-03/message/0

我在使用 jaxb2-maven-plugin 时遇到了这个问题。我发现了一个与 maven-jabx2-plugin 相关的 jira 问题 - https://java.net/projects/maven-jaxb2-plugin/lists/issues/archive/2014-03/message/0

According to this issue Stephan202 suggested using properties-maven-plugin which worked like charm. Here is a sample code from his post -

根据这个问题,Stephan202 建议使用 properties-maven-plugin ,它的作用就像魅力一样。这是他的帖子中的示例代码 -

<plugin>
<!-- We use this plugin to ensure that our usage of the
maven-jaxb2-plugin is JDK 8 compatible in absence of a fix
for https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80. -->
    <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>file,http</value>
            </property>
        </properties>
    </configuration>
</plugin>

回答by Neil Piper

Re; the post - "I needed a solution that doesn't use alpha versions as that is my companies rules. –"

关于; 帖子 - “我需要一个不使用 alpha 版本的解决方案,因为这是我公司的规则。-”

Changing the version to 1.0 & the value to 'all' got it working for me:

将版本更改为 1.0 并将值更改为“全部”使其对我有用:

<plugin>
<!-- We use this plugin to ensure that our usage of the
maven-jaxb2-plugin is JDK 8 compatible in absence of a fix
for https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80. -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <!--
    <version>1.0-alpha-2</version> -->
    <version>1.0.0</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>
        </properties>
    </configuration>
</plugin>

回答by user6280333

It has worked for me :

它对我有用:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>process-sources</phase>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <vmArgs>
                    <arg>-Djavax.xml.accessExternalSchema=all</arg>
                </vmArgs>
                <keep>true</keep>
                <verbose>true</verbose>
                <wsdlDirectory>${project.build.directory}/wsdl</wsdlDirectory>
                <wsdlFiles>
                    <wsdlFile>ServiceWsService.wsdl</wsdlFile>
                </wsdlFiles>
                <bindingFiles>
                    <bindingFile>custom-binding.xml</bindingFile>
                    <bindingFile>custom-binding2.xml</bindingFile>
                </bindingFiles>                         
            </configuration>
        </execution>
    </executions>
</plugin>