28

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.

I know I can pass in jvm args on the command line eg: 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?

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

lexicore
  • 42,748
  • 17
  • 132
  • 221
Josh
  • 818
  • 2
  • 16
  • 27

7 Answers7

34

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.

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

This sets precisely javax.xml.accessExternalSchema=all.

Please see the documentation.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • Thanks! Switching from the codehaus plugin to a recent version of yours solved the issue. No added config needed :) – Geert Schuring Jul 09 '15 at 12:16
  • In the documentation its mention that ACCESS_EXTERNAL_SCHEMA has default value of all, so why do we need to set it? – Amer Qarabsa Oct 30 '17 at 09:32
  • Neither this answer nor the documentation linked shows how to set the accessExternalSchema in the pom. The accessExternalSchema option is mentioned, but not clearly shown where it goes. – Graham Leggett Nov 19 '20 at 20:10
23

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

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

<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>
Amit Misra
  • 371
  • 2
  • 4
  • nice answer - thanks. I needed a solution that doesn't use alpha versions as that is my companies rules. – Josh Jan 08 '15 at 16:39
  • 1
    If you don't have truly external schemas, it can work to just the property to `file`. This is what I needed to get org.jvnet.ws.wadl:wadl-client-plugin:1.1.6 working with Java 8. – Donal Fellows Jul 04 '16 at 13:54
  • Thank God that I've found this answer after half a day of a fun! – Vitalii Mar 11 '21 at 18:23
9

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

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

<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>
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
Neil Piper
  • 91
  • 1
  • 1
1

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>
Draken
  • 3,134
  • 13
  • 34
  • 54
0

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

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

creechy
  • 405
  • 2
  • 3
0

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.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • This is relevant to the new XML security properties in JAXB 1.5, introduced in Java 8, so it shouldn't actually be "Maven global" but rather just for schema compilation. http://docs.oracle.com/javase/tutorial/jaxp/properties/properties.html – lexicore Oct 13 '14 at 22:36
  • Who knows if he has a Maven plugin, he uses your maven plugin, or he uses some other maven plugin? – bmargulies Oct 13 '14 at 22:56
  • @margulies I think the OP clearly stated that he *is* using one of the JAXB2 Maven plugins ("I have a maven plugin (jaxb2)...") and the tag suggests he uses mine. An note my answer has an "If ...". – lexicore Oct 13 '14 at 23:00
0

For maven-jaxb2-plugin version 2.5.0 trying to generate from DTD and spitting

org.xml.sax.SAXParseException: External parsing is disabled. Cannot parse URI: ...

it helped adding the following to plugin configuration

     <configuration>
         ...
         <externalEntityProcessing>true</externalEntityProcessing>
     </configuration>
Alexander
  • 381
  • 3
  • 11