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

Jos*_*osh 25 java maven maven-jaxb2-plugin

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

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

是否可以在pom中设置此jvm arg,以便我不必每次都在命令行中键入它?

(除此之外 - 这个jvm arg是必需的,以便它可以与JAVA-8一起使用.它适用于JAVA-7)

lex*_*ore 32

这与Java 8中引入的JAXB 1.5中的新XML安全属性相关.这就是为什么您的构建现在在Java 8上失败但与Java 7一起使用.

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

这准确地说明了javax.xml.accessExternalSchema=all.

请参阅文档.


小智 20

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

根据这个问题,Stephan202建议使用像魅力一样的属性-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>
Run Code Online (Sandbox Code Playgroud)


小智 8

回覆; 帖子 - "我需要一个不使用alpha版本的解决方案,因为这是我的公司规则."

将版本更改为1.0并将值更改为"all"使其适用于我:

<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>
Run Code Online (Sandbox Code Playgroud)