Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only the first execution bloc works #15

Closed
thierryler opened this issue Oct 30, 2014 · 5 comments
Closed

Only the first execution bloc works #15

thierryler opened this issue Oct 30, 2014 · 5 comments

Comments

@thierryler
Copy link

Hello,

In my project, I have many XSD files (a.xsd, b.xsd, c.xsd, d.xsd, etc.) that represent my domain and I use the maven-jaxb2-plugin to generate the class files.

I also have another XSD file (xyz.xsd) that represents another part of my domain.

Therefore, in my pom.xml, i've setup 2 executions :

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.9.0</version>
    <executions>
        <execution>
            <id>xjc-schema-abcde</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaExcludes>
                    <include>xyz.xsd</include>
                </schemaExcludes>
                <schemaDirectory>src/main/xsd</schemaDirectory>
                <bindingDirectory>src/main/xsd</bindingDirectory>
                <generatePackage>com.mycorp.foo</generatePackage>
                <bindingIncludes>
                    <include>bindings-1.xml</include>
                </bindingIncludes>
                <args>
                    <arg>-Xinheritance</arg>
                    <arg>-extension</arg>
                    <arg>-Xnamespace-prefix</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.8.4</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-namespace-prefix</artifactId>
                        <version>1.1</version>
                    </plugin>
                </plugins>
            </configuration>
        </execution>

        <execution>
            <id>xjc-schema-xyz</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaIncludes>
                    <include>xyz.xsd</include>
                </schemaIncludes>
                <schemaDirectory>src/main/xsd</schemaDirectory>
                <bindingDirectory>src/main/xsd</bindingDirectory>
                <generatePackage>net.acmee.xyz</generatePackage>
                <bindingIncludes>
                    <include>bindings-xyz.xml</include>
                </bindingIncludes>
                <args>
                    <arg>-Xinheritance</arg>
                    <arg>-extension</arg>
                    <arg>-Xnamespace-prefix</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.8.4</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-namespace-prefix</artifactId>
                        <version>1.1</version>
                    </plugin>
                </plugins>
            </configuration>
        </execution>
    </executions>
</plugin>

I've tried each execution bloc separately and they both work. But when there is more than one execution bloc, only the first one is executed.

Did I write something wrong ?

Th.

Tested on Java 8, Maven 3

@highsource
Copy link
Owner

This is a duplicate for:

See the recommendations here:

Why do you need multiple executions? Because of the generatePackage? If
so then I generally don't recommend using generatePackage. Use
schemaBindings in your binding file instead.
Current workarounds:

  • Use a single execution and specify schemaBindings instead of
    generatePackage.
  • Compile your schema in different maven modules.
  • Specify a different generateDirectory per execution.

Technicaly this issue will not be fixed. If you need several executions (I
don't think you do, generatePackage is a poor reason) then you have to
provide individual generateDirectorys per execution. So in the next
version of the plugin I will only add warnings for this case.

The reason why it will not be fixed is that if you have different
executions generating into the same directoy, there is almost no means to
check if everything is up-to-date, which is very important for incremental
builds.

On Thu, Oct 30, 2014 at 10:04 AM, Thierry Leriche-Dessirier <
[email protected]> wrote:

Hello,

In my project, I have many XSD files (a.xsd, b.xsd, c.xsd, d.xsd, etc.)
that represent my domain and I use the maven-jaxb2-plugin to generate the
class files.

I also have another XSD file (xyz.xsd) that represents another part of my
domain.

Therefore, in my pom.xml, i've setup 2 executions :

org.jvnet.jaxb2.maven2 maven-jaxb2-plugin 0.9.0 xjc-schema-abcde generate xyz.xsd src/main/xsd src/main/xsd com.mycorp.foo bindings-1.xml -Xinheritance -extension -Xnamespace-prefix org.jvnet.jaxb2_commons jaxb2-basics 0.8.4 org.jvnet.jaxb2_commons jaxb2-namespace-prefix 1.1
    <execution>
        <id>xjc-schema-xyz</id>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <schemaIncludes>
                <include>xyz.xsd</include>
            </schemaIncludes>
            <schemaDirectory>src/main/xsd</schemaDirectory>
            <bindingDirectory>src/main/xsd</bindingDirectory>
            <generatePackage>net.acmee.xyz</generatePackage>
            <bindingIncludes>
                <include>bindings-xyz.xml</include>
            </bindingIncludes>
            <args>
                <arg>-Xinheritance</arg>
                <arg>-extension</arg>
                <arg>-Xnamespace-prefix</arg>
            </args>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>0.8.4</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-namespace-prefix</artifactId>
                    <version>1.1</version>
                </plugin>
            </plugins>
        </configuration>
    </execution>
</executions>

I've tried each execution bloc separately and they both work. But when
there is more than one execution bloc, only the first one is executed.

Did I write something wrong ?

Th.

Tested on Java 8, Maven 3


Reply to this email directly or view it on GitHub
#15.

@thierryler
Copy link
Author

Thx for the quick answer.

I do have multiple executions because of the generatePackage and because I need to setup different super class for each domain.

I've tried this :

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.9.0</version>
    <executions>
        <execution>
            <id>xjc-schema-all</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaDirectory>src/main/xsd</schemaDirectory>
                <bindingDirectory>src/main/xsd</bindingDirectory>
                <bindingIncludes>
                    <include>bindings-abcde.xml</include>
                    <include>bindings-xyz.xml</include>
                </bindingIncludes>
                <args>
                    <arg>-Xinheritance</arg>
                    <arg>-extension</arg>
                    <arg>-Xnamespace-prefix</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.8.4</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-namespace-prefix</artifactId>
                        <version>1.1</version>
                    </plugin>
                </plugins>
            </configuration>
        </execution>
    </executions>
</plugin>

with bindings-abcde.xml :

<?xml version="1.0"?>
<jxb:bindings ...>
    <jxb:bindings schemaLocation="mdata-commons.xsd">
        <jxb:schemaBindings>
            <jxb:package name="com.mycorp.foo" />
        </jxb:schemaBindings>
        <jxb:bindings>
            <namespace:prefix name="mda" />
        </jxb:bindings>
    </jxb:bindings>

    <jxb:globalBindings>
        <!-- use Calendar instead of XMLGregorianCalendar -->
        <jxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
            parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
            printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />

        <jxb:javaType name="java.util.Calendar" xmlType="xs:date"
            parseMethod="javax.xml.bind.DatatypeConverter.parseDate" printMethod="javax.xml.bind.DatatypeConverter.printDate" />

        <jxb:javaType name="java.util.Calendar" xmlType="xs:time"
            parseMethod="javax.xml.bind.DatatypeConverter.parseTime" printMethod="javax.xml.bind.DatatypeConverter.printTime" />
    </jxb:globalBindings>
</jxb:bindings>

And bindings-xyz.xml :

<?xml version="1.0"?>
<jxb:bindings ...>
    <jxb:bindings schemaLocation="xyz.xsd">
        <jxb:schemaBindings>
            <jxb:package name="net.acmee.xyz" />
        </jxb:schemaBindings>
        <jxb:bindings>
            <namespace:prefix name="tns" />
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

All the class are generated into the package "com.mycorp.foo". I expected the class from "xyz.xsd" to be generated into "net.acmee.xyz".

@thierryler
Copy link
Author

I added true and it makes my first example work. with specific binding files and removed.

Thx

@highsource
Copy link
Owner

Sorry, did not quite understood your last comment: "I added true and it
makes my first example work. with specific binding files and removed".

Where did you add "true", what was "removed"?

Different superclass per domain may be a valid reason.

Is it resolved for you or there's something I can do?

On Thu, Oct 30, 2014 at 10:54 AM, Thierry Leriche-Dessirier <
[email protected]> wrote:

I added true and it makes my first example work. with specific binding
files and removed.

Thx


Reply to this email directly or view it on GitHub
#15 (comment)
.

@thierryler
Copy link
Author

Hi High,

Humm the tag was removed from the comment.

I wrote :

<forceRegenerate>true</forceRegenerate>

So my pom.xml now looks like :

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.9.0</version>
    <executions>
        <execution>
            <id>xjc-schema-abcde</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaIncludes>
                    <include>mdata-commons.xsd</include>
                    <include>a.xsd</include>
                    <include>b.xsd</include>
                    <include>c.xsd</include>
                    <include>d.xsd</include>
                    <include>e.xsd</include>
                </schemaIncludes>
                <schemaExcludes>
                    <include>xyz.xsd</include>
                </schemaExcludes>
                <schemaDirectory>src/main/xsd</schemaDirectory>
                <bindingDirectory>src/main/xsd</bindingDirectory>
                <bindingIncludes>
                    <include>bindings-abcde.xml</include>
                </bindingIncludes>
                <args>
                    <arg>-Xinheritance</arg>
                    <arg>-extension</arg>
                    <arg>-Xnamespace-prefix</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.8.4</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-namespace-prefix</artifactId>
                        <version>1.1</version>
                    </plugin>
                </plugins>
                <forceRegenerate>true</forceRegenerate>
            </configuration>
        </execution>

        <execution>
            <id>xjc-schema-xyz</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaIncludes>
                    <include>xyz.xsd</include>
                </schemaIncludes>
                <schemaExcludes>
                    <include>mdata-commons.xsd</include>
                    <include>a.xsd</include>
                    <include>b.xsd</include>
                    <include>c.xsd</include>
                    <include>d.xsd</include>
                    <include>e.xsd</include>
                </schemaExcludes>
                <schemaDirectory>src/main/xsd</schemaDirectory>
                <bindingDirectory>src/main/xsd</bindingDirectory>
                <bindingIncludes>
                    <include>bindings-xyz.xml</include>
                </bindingIncludes>
                <args>
                    <arg>-Xinheritance</arg>
                    <arg>-extension</arg>
                    <arg>-Xnamespace-prefix</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.8.4</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-namespace-prefix</artifactId>
                        <version>1.1</version>
                    </plugin>
                </plugins>
                <forceRegenerate>true</forceRegenerate>
            </configuration>
        </execution>
    </executions>
</plugin>

I added the tag "forceRegenerate" and removed "generatePackage".

Actually, no more help is needed for my problem.

Thx a lot.
Th.

laurentschoelens pushed a commit to laurentschoelens/jaxb-tools that referenced this issue May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants