17

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?

Puce
  • 37,247
  • 13
  • 80
  • 152

4 Answers4

18

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>
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • Thanks for your answer. Unfortunately it did not work. (unknown parameter -Duser.language=en). I file an issue here: https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-87 – Puce Mar 23 '14 at 22:32
  • As this is answer is from the author of the maven-jaxb2-plugin and thus likely to be the best answer there is, I accept it. – Puce Mar 23 '14 at 22:33
  • Thank you for the report, I'll be looking into it. – lexicore Mar 24 '14 at 08:21
  • @Puce Please see the update. This feature is implemented now. – lexicore Oct 03 '14 at 21:39
  • Great, thanks, I will try it out once version 0.10.0 is available. – Puce Oct 03 '14 at 21:53
  • 1
    @Puce 0.10.0 is released now: https://github.com/highsource/maven-jaxb2-plugin/releases/tag/0.10.0 – lexicore Oct 05 '14 at 22:18
5

in windows command line:

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

tested with jdk9

benez
  • 1,856
  • 22
  • 28
0

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.

Community
  • 1
  • 1
boumbh
  • 2,010
  • 1
  • 19
  • 21
0

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.