jaxb-tools icon indicating copy to clipboard operation
jaxb-tools copied to clipboard

schemaDirectory/schemaIncludes don't seem to work as expected

Open robertpatrick opened this issue 1 year ago • 3 comments

I have an existing Java project that uses JAXB 2.x that I am trying to move to JAXB 3.0 and as such, have modified the project to use the org.jvnet.jaxb:jaxb-maven-plugin:3.0.2 plugin's generate goal.

The schemas are located in subdirectories under src/main/resources. For example:

src/main/resources/com/mycompany/package1/package1.xsd
src/main/resources/com/mycompany/package2/package2.xsd
src/main/resources/com/mycompany/package3/package3.xsd

I have tried all sorts of values for schemaDirectory and schemaIncludes and nothing seems to work since I get this message from running the build:

[INFO] --- jaxb:3.0.2:generate (generate-package1-classes) @ comdev ---
[WARNING] No schemas to compile. Skipping XJC execution. 

My plugin declaration is pretty simple so I do not understand why this isn't working:

            <plugin>
                <groupId>org.jvnet.jaxb</groupId>
                <artifactId>jaxb-maven-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>generate-package1-classes</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <specVersion>3.0</specVersion>
                            <episodeFile>src/main/resources/jaxb-episode.xsl</episodeFile>
                            <schemaDirectory>src/main/resources/com/mycompany/package1</schemaDirectory>
                            <schemaIncludes>
                                <include>package1.xsd</include>
                            </schemaIncludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

If I place all of my schema in src/main/resources directly and remove the schemaDirectory and schemaIncludes, the plugin finds the schemas and is able to compile them.

robertpatrick avatar Dec 10 '24 22:12 robertpatrick

Same issue with 4.0.8. Can someone please explain how these configuration parameters are supposed to work?

robertpatrick avatar Dec 12 '24 15:12 robertpatrick

Hi @robertpatrick

I'll try to reproduce your issue and see what could be wrong in your configuration.

Regards, Laurent

laurentschoelens avatar Dec 13 '24 05:12 laurentschoelens

Could you provide with a MRE (Minimal Reproductible Exemple) please ? I didn't manage to get the same problem as yours 😞

laurentschoelens avatar Dec 13 '24 11:12 laurentschoelens

@robertpatrick could you provide MRE please ?

laurentschoelens avatar Apr 11 '25 08:04 laurentschoelens

@laurentschoelens I abandoned my use of this plugin for now and am using the exec-maven-plugin to run com.sun.tools.xjc.Driver directly to work around the problem. Sorry...

robertpatrick avatar Apr 11 '25 13:04 robertpatrick

No problem @robertpatrick

Maybe you didnt catch my previous comments asking MRE. If you got any time, please feel free to provide it so we can analyse this more deeply and check if it is a bug or only documentation which is unclear.

Thanks

laurentschoelens avatar Apr 11 '25 15:04 laurentschoelens

@robertpatrick

What was in the src/main/resources/jaxb-episode.xsl file ? Was it the same file for each set ?

Thanks

laurentschoelens avatar Apr 15 '25 18:04 laurentschoelens

@laurentschoelens I abandoned my use of this plugin for now and am using the exec-maven-plugin to run com.sun.tools.xjc.Driver directly to work around the problem. Sorry...

Could you share the plugin's configuration as equivalent of jaxb-maven-plugin @robertpatrick ? I think I got your problem

laurentschoelens avatar Apr 16 '25 12:04 laurentschoelens

@laurentschoelens. I am not allowed to post the complete content of the file but it is basically doing this:

   <xsl:output method="xml" encoding="UTF-8" indent="yes" xmlns:xalan="http://xml.apache.org/xalan" xalan:indent-amount="2" standalone="yes"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="comment()"/>
  
  <xsl:template match="/jaxb:bindings/jaxb:bindings">
    <xsl:copy>
      <xsl:attribute name="if-exists">true</xsl:attribute>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

Yes, it was the same file for execution of the plugin but not the file was not the same across all executions (though the content was very similar).

Could you share the plugin's configuration as equivalent of jaxb-maven-plugin @robertpatrick ? I think I got your problem

I never checked that code into source control so I no longer have it.

robertpatrick avatar Apr 16 '25 14:04 robertpatrick

Thanks for your many feedback @robertpatrick

One more question : did you try your code on Windows platform ou Unix platform ? I guess Windows

laurentschoelens avatar Apr 16 '25 20:04 laurentschoelens

@laurentschoelens macOS 😁

robertpatrick avatar Apr 16 '25 23:04 robertpatrick

Well then, here is my diagnostic : the only way to have the same output as yours is to have the schemaDirectory pointing to a non existing directory (no log is produces) or having schemaIncludes too restrictive.

schemaIncludes is of regex type which is case-sensitive. Having file.xsd defined where only File.xsd exists will lead to nothing to compile in the end. By default, schemaIncludes is *.xsd value. Maybe this should be enough for your configuration ?

laurentschoelens avatar Apr 17 '25 06:04 laurentschoelens

Umm, no. The message used to create the issue shows clearly the structure and plugin configuration. I can assure you that the relative paths were correct and do exist. Maybe the plugin wasn’t handling the paths correctly?

robertpatrick avatar Apr 17 '25 11:04 robertpatrick

Umm, no. The message used to create the issue shows clearly the structure and plugin configuration. I can assure you that the relative paths were correct and do exist. Maybe the plugin wasn’t handling the paths correctly?

I've tested with 4.0.8 and wasn't able to reproduice your issue. Maybe it was something wrong somewhere or some outer directory triggering this thing.

I'll add some UT to the main code to avoid any regression on your problem but also add some extra warnings if nothing is found and not on the default config (base schema directory or schema incluses...). That would clearly help solve configuration problems to have extra output I guess.

@mattrpav what do you think of this ? ^

laurentschoelens avatar Apr 17 '25 12:04 laurentschoelens

I'd like to see output with Maven debug logging turned on to see if additional clues pop-up.

One thing on is the episode entry looks incorrect, as it looks to be pointed to a stylesheet

<episodeFile>src/main/resources/jaxb-episode.xsl</episodeFile>

mattrpav avatar Apr 17 '25 13:04 mattrpav

@robertpatrick could you give a new try to the plugin with -X -e mvn flags enabled ?

@mattrpav my point was : having configured some properties but having no files match gives no clue on some situations (like schemaDirectory pointing to a non existing directory)

laurentschoelens avatar Apr 23 '25 13:04 laurentschoelens