7

I am trying to generated sources from two XSD schemas. My JAXB maven plugin looks like this:

<plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
    <artifactId>maven-jaxb-plugin</artifactId>
    <version>1.1.1</version>
    <executions>
        <execution>
            <id>GenerateKenexa</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <includeBindings>
                    <includeBinding>**/jaxb-bindings-kenexa.xml</includeBinding>
                </includeBindings>
                <includeSchemas>
                    <includeSchema>**/KenexaXMLConfiguration.xsd</includeSchema>
                </includeSchemas>
            </configuration>
        </execution>
        <execution>
            <id>GenerateTalentQ</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <includeBindings>
                    <includeBinding>**/jaxb-bindings-talentq.xml</includeBinding>
                </includeBindings>
                <includeSchemas>
                    <includeSchema>**/TalentQXMLConfiguration.xsd</includeSchema>
                </includeSchemas>
            </configuration>
        </execution>
    </executions>
</plugin>

The first one gets generated fine. But the second one does not. I see in the maven output:

[INFO] --- maven-jaxb-plugin:1.1.1:generate (GenerateKenexa) @ online.tests.management ---
[INFO] Compiling file:/D:/Projects/GTIWebApplications/gti_online_tests_management/src/main/resources/xsd/KenexaXMLConfiguration.xsd
[INFO] Writing output to D:\Projects\GTIWebApplications\gti_online_tests_management\target\generated-sources\xjc
[INFO] 
[INFO] --- maven-jaxb-plugin:1.1.1:generate (GenerateTalentQ) @ online.tests.management ---
[INFO] files are up to date

It says that files are up to date, but they aren't even generated. What might be wrong?

edorian
  • 38,542
  • 15
  • 125
  • 143
Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143

4 Answers4

21

For people coming in to this question as I did, a year later :/

The problem persists in maven-jaxb2-plugin aswell, it's probably some sort of bug in 0.8.3. When you generate the files into the same directory, the plugin "thinks" that the files have allready been generated and skips that second execution.

I found that in order to generate the second execution you will have to set the argument

<forceRegenerate>true</forceRegenerate>

In the configuration section.

Jan Nielsen
  • 329
  • 4
  • 9
  • 1
    It has to mentioned though that meanwhile the use of this forceRegenerate setting is strongly discouraged; See here: https://github.com/highsource/maven-jaxb2-plugin/wiki/Do-Not-Use-forceRegenerate – doct0re Nov 18 '21 at 13:50
5

I solved the problem. I have changed the maven jaxb plugin into maven jaxb2 plugin and now everything works. Now my maven configuration looks like this:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.2</version>
    <executions>
        <execution>
            <id>GenerateKenexa</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                <schemaIncludes>
                    <include>KenexaXMLConfiguration.xsd</include>
                </schemaIncludes>
                <generatePackage>com.groupgti.onlinetest.kenexa.jaxb</generatePackage>
                <generateDirectory>${project.build.directory}/generated-sources/kenexa</generateDirectory>
            </configuration>
        </execution>
        <execution>
            <id>GenerateTalentQ</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                <schemaIncludes>
                    <include>TalentQXMLConfiguration.xsd</include>
                </schemaIncludes>
                <generatePackage>com.groupgti.onlinetest.talentq.jaxb</generatePackage>
                <generateDirectory>${project.build.directory}/generated-sources/talentq</generateDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143
2

I am using jaxb2 while still was facing the problem when I reached here. I added the below piece into config from other folks answers and it works now. For previous answers the part that did the trick should be:

<generateDirectory>${project.build.directory}/generated-sources/kenexa</generateDirectory>

Also a unique execution id is needed

<id>GenerateKenexa</id>

But different directories make the code lies into two top level packages, so at last I am using:

<forceRegenerate>true</forceRegenerate>
Peng Zhang
  • 21
  • 2
  • 1
    When using separate directories, you should no longer need , at least not with version 0.12.1 of the plugin. – JSamir Mar 01 '17 at 10:19
1

First, I would recommend to specify separate output folders for each xsd <outputdirectory>${basedir}/target/generated-sources/xjc</outputdirectory>

And second, try to set it up as separate plugin entries, no separate executions:

<plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
...
<includeSchema>**/KenexaXMLConfiguration.xsd...
...
</plugin>
<plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
...
<includeSchema>**/TalentQXMLConfiguration.xsd...
...
</plugin>
Grigory Katkov
  • 421
  • 4
  • 9
  • If I separate those into different plugins only last one gets executed, first one does not, and my code does not compile. And where I should add this ? There is no such element available. – Paulius Matulionis Aug 31 '12 at 11:26