mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
106 stars 77 forks source link

Source vs. bytecode arguments #88

Closed orange-buffalo closed 6 years ago

orange-buffalo commented 7 years ago

Hi,

Does schemagen goal work with compiled classes as an input? As I understood from Advanced topic: SchemaGen source vs. bytecode arguments, it should be possible to use compiled classes. But my attempts to do so failed.

I tried to specify the fully-qualified class name:

<execution>
    <id>schemagen</id>
    <phase>process-classes</phase>
    <goals>
        <goal>schemagen</goal>
    </goals>
    <configuration>
        <sources>
            <source>foo.Bar</source>
        </sources>
    </configuration>
</execution>

But plugin complains about misconfiguration:

[INFO] Ignored given or default sources [foo.Bar], since it is not an existent file or directory.
...
+=================== [Incorrect Plugin Configuration Detected]
|
| Property : sources
| Problem  : At least one Java Source file has to be included.
|
+=================== [End Incorrect Plugin Configuration Detected]

Then I tried to use the target/classes folder:

<execution>
    <id>schemagen</id>
    <phase>process-classes</phase>
    <goals>
        <goal>schemagen</goal>
    </goals>
    <configuration>
        <sources>
            <source>target/classes/foo</source>
        </sources>
    </configuration>
</execution>

I can see in logs that classes are taken into consideration:

+=================== [Filtered sources]
...
| 18 Results:
| [1/18]: file:/.../target/classes/foo/Bar.class
...

But then build fails with parser error:

Caused by: com.thoughtworks.qdox.parser.ParseException: syntax error @[2,4] in file:/.../target/classes/foo/Bar.class
    at com.thoughtworks.qdox.parser.impl.Parser.yyerror(Parser.java:1683)
    at com.thoughtworks.qdox.parser.impl.Parser.yyparse(Parser.java:1805)
    at com.thoughtworks.qdox.parser.impl.Parser.parse(Parser.java:1664)
    at com.thoughtworks.qdox.library.SourceLibrary.parse(SourceLibrary.java:210)
    at com.thoughtworks.qdox.library.SourceLibrary.parse(SourceLibrary.java:186)
    at com.thoughtworks.qdox.library.SourceLibrary.addSource(SourceLibrary.java:141)
    at com.thoughtworks.qdox.library.SortedClassLibraryBuilder.addSource(SortedClassLibraryBuilder.java:173)
    at com.thoughtworks.qdox.JavaProjectBuilder.addSource(JavaProjectBuilder.java:150)
    at org.codehaus.mojo.jaxb2.schemageneration.AbstractXsdGeneratorMojo.getSchemaGeneratorSourceFiles(AbstractXsdGeneratorMojo.java:704)

Could you please shed some light on how and if plugin works with compiled bytecode?

lennartj commented 6 years ago

We need to update the documentation to clarify this. Also, we would need an integration test - peering through our ITs it seems we have none doing this at the moment.

However - one thing is clear from running SchemaGen: It cannot cope with both Source files and Bytecode files in one compilation.

nsmith00 commented 5 years ago

I've been trying in vain to get the schemagen plugin to process bytecode class files. Could you please elaborate on the statement "If you would like to operate on bytecode files only, the plugin configuration must remove the sourcePath from the paths where it looks for jaxb sources."

Either I get schemagen complaining about no sources or that it cannot parse the class file.

Many thanks in advance!

tmy1313 commented 4 years ago

Has anyone been able to do this? I have the same exact issue as the OP. I know this is an old thread, but hoping to get some insight.

Thanks.

lennartj commented 4 years ago

I just tested with raw schemagen commands to attempt to get it to synthesize schema from bytecode files - and while it creates a schema file, that file seems to be empty.

Hm.