mojohaus / jaxb2-maven-plugin

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

auto generate java classes based on the multiple xsd file exist in different packages #125

Open ksrkon opened 5 years ago

ksrkon commented 5 years ago

Hi,

I had a below requirement.

I have to generate java classes in the similar package structure where xsd files are exist using the maven plugin.

Below are the xsd file paths exist in different directories. some of these xsd files has import of another xsds too. com.test.dir1 --> test1.xsd com.test.dir2 --> test2.xsd com.test.dir3 --> test3.xsd

Now I need to generate java classes for the above xsd files and make sure that those are generated in the similar paths where xsd files exist like mentioned below.

JAxb GeneratedClasses

com.test.dir1 --> test1.java com.test.dir2--> test2.java com.test.dir3 --> test3.java

How we can achieve using the jaxb maven plugin?

Thank you.

jpl-jengelke commented 3 years ago

https://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/example_xjc_basic.html#Example_5:_Multiple_schemas_with_different_configuration

fvpaz commented 2 years ago

https://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/example_xjc_basic.html#Example_5:_Multiple_schemas_with_different_configuration

Hello @jpl-jengelke Can you help me?

I follow guide but XJC don't found my XSD files when costume configuration with \

Enviroment: jaxb2-maven-plugin:2.5.0 Command: mvn jaxb2:xjc

Error Msg:

[INFO] 
[INFO] --- jaxb2-maven-plugin:2.5.0:xjc (default-cli) @ SoapSample ---
[INFO] Created EpisodePath [C:\myDir\Development\WorkSpace\SoapSample\target\generated-sources\jaxb\META-INF\JAXB]: true
[INFO] Ignored given or default xjbSources [C:\myDir\Development\WorkSpace\SoapSample\src\main\xjb], since it is not an existent file or directory.
[WARNING] No XSD files found. Please check your plugin configuration.

POM.xml

                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.5.0</version>
                <executions>
                    <execution>
                        <id>xjc-schema1</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/main/resources/schemas/schema1</source>
                            </sources>

                            <!-- Package name of the generated sources. -->
                            <packageName>com.example.soapsample.stub.schema1</packageName>
                            <outputDirectory>com.example.soapsample.stub.schema1</outputDirectory>
                        </configuration>
                    </execution>

                    <execution>
                        <id>xjc-schema2</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/main/resources/schemas/schema2</source>
                            </sources>
                            <arguments>
                                <argument>-XautoNameResolution</argument>
                            </arguments>
                            <!-- Package name of the generated sources. -->
                            <packageName>com.example.soapsample.stub.schema2</packageName>

                            <!--
                                Don't clear the output directory before generating the sources.
                                Clearing the output directory removes the se.west schema from above.
                            -->
                            <clearOutputDir>false</clearOutputDir>
                        </configuration>
                    </execution>
                </executions>
dragneelfps commented 2 years ago

I am also getting no XSD found when using source tag in multiple executions. Seems like it is ignored.

fvpaz commented 2 years ago

@dragneelfps I solved, it's a problem of the config in the POM not of the Plugin:

Stack overflow

For multiple executions, You have to declare the plugin dependency in PluginManagement and in Plugin but without the version: Sample:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxws-maven-plugin</artifactId>
                    <version>2.5.0</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
            </plugin>
        <plugins>
    <build>
dragneelfps commented 2 years ago

Actually the issue is that I assumed running mvn jaxb2:xjc will run each execution and use its specific configuration parameters, but what happens is that it only uses plugin-level declared configuration. To run each execution separately, you need to use something like mvn jaxb2:xjc@<executionID>. Also, an mvn package will pick up execution level configuration properly. Not sure how that works since I dont have deep knowledge about maven yet.

fvpaz commented 2 years ago

@dragneelfps I realized it in mvn jaxb2:xjc only run an execution and I stay with your tips. I execute mvn compile for running all executions,