Question

When I generate JAXB classes using the maven-jaxb2-plugin I get classes with partial(!?) German Javadoc. (My default locale: de_CH)

What I want: English Javadoc

I tried to set the maven opts: -Duser.language=en -Duser.country=US but it had no effect.

How can I generate JAXB classes with English Javadoc?

Here is the Javadoc for some JAXB classes with partial German Javadoc: http://drombler.sourceforge.net/DromblerACP/docs/site/0.2.1-SNAPSHOT/apidocs/org/drombler/acp/core/action/jaxb/package-frame.html

Here is the according XSD: http://sourceforge.net/p/drombler/drombler-acp/ci/default/tree/drombler-acp-core-action/src/main/resources/actions.xsd

Here is the according POM: http://sourceforge.net/p/drombler/drombler-acp/ci/default/tree/drombler-acp-core-action/pom.xml

Related JAXB Issue:

https://java.net/jira/browse/JAXB-1001

Any workaround?

Was it helpful?

Solution

You can pass arbitrary properties to XJC using the args/arg element in the configuration of the maven-jaxb2-plugin:

<configuration>
    <extension>true</extension>
    <args>
        <arg>-Duser.language=en</arg>
    </args>
</configuration>

These arguments will be just passed to XJC.

However I have no idea if -Duser.language=en -Duser.country=US are the right options. Anyway the args/arg will be passed to XJC. If it does not work please file an issue here.

Disclaimer: I'm the author of maven-jaxb2-plugin.

Update

This feature is implemented in the version 0.10.0. Now you can do the following:

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <configuration>
                <locale>es</locale>
            </configuration>
        </plugin>

OTHER TIPS

in windows command line:

> SET JAVA_TOOL_OPTIONS=-Duser.language=en -Duser.country=US -Dfile.encoding=UTF-8
> xjc .

tested with jdk9

This bug seems to be a regression as the issue does not exist in the previous versions.

So maybe you could use org.codehaus.mojo:jaxb2-maven-plugin:1.5...

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>
</plugin>

Note: in the 1.5, multi-executions did not work (see jaxb2-maven-plugin only executing first execution). I don't know if they will ever get their plug-in right.

I needed this as well....the only reasonable workaround (for other plugins like the mojohaus/jaxb2-maven-plugin) is to invoking Locale.setDefault(YOURLANGUAGE) before the generation of the files (in my case generation of java files from xsd with xjc)...

You could for example use the maven antrun plugin to set the default locale before the execution of the generation:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>setLocaleFixedToUS</id>
            <phase>initialize</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <target>
            <scriptdef name="setLocaleFixedToUS" language="javascript">
                <![CDATA[
                    importClass(java.util.Locale);
                    actualDefault = Locale.getDefault();
                    project.setProperty("actual-default-locale", actualDefault);
                    Locale.setDefault(Locale.US);
                ]]>
            </scriptdef>
            <setLocaleFixedToUS />
        </target>
    </configuration>
</plugin>

All other solutions with setting -Duser.language=en -Duser.country=US or commandline arguments didn't work for me either.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top