Search code examples
maven-pluginjibx

jibx-maven-plugin 1.2.3 schema-codegen goal <schemaLocation> value ignored


I am trying to use jibx-maven plugin 1.2.3 for generating Java Source Code from a Schema file.

Following is the plugin config in my pom.xml

<build>
<plugins>
    <!--
         To use the JiBX Maven Plugin in your project you have to add it 
         to the plugins section of your POM. 
     -->
    <plugin>
        <groupId>org.jibx</groupId>
        <artifactId>jibx-maven-plugin</artifactId>
        <version>1.2.3</version>
        <executions>
           <execution>
                <goals>
                  <goal>schema-codegen</goal>
                </goals>
                <configuration>
                   <schemaLocation>src/main/resources</schemaLocation>
                   <options>
                       <package>com.poc.jibx</package>
                   </options>
                </configuration>
           </execution>
        </executions>
    </plugin>
</plugins>
 </build>

When I try to run the goal using command: mvn jibx:schema-codegen

I get the following output

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building jibx-sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- jibx-maven-plugin:1.2.3:schema-codegen (default-cli) @ jibx-sample ---
[INFO] Generating Java sources in target/generated-sources from schemas available in src/main/config...
Loaded and validated 0 specified schema(s)
Total classes in model: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.691s
[INFO] Finished at: Thu Sep 22 20:11:33 IST 2011
[INFO] Final Memory: 6M/71M
[INFO] ------------------------------------------------------------------------

As can be seen in the output the default schema location is being searched for i.e. src/main/config instead of my the configured location src/main/resources.

I came across the following JIRA which says the the above plugin config is appropriate and should work prefectly. http://jira.codehaus.org/browse/JIBX-450

However it is not working in my case.Am I missing anything else for making this work?

Thanks,
Jignesh


Solution

  • Jignesh,

    Actually, your first pom should have worked fine. khmarbaise is correct, it is considered good practice to place your schema definitions in the /src/main/config directory and make sure they have an .xsd extension.

    Here is a corrected project file. I am using your schema location. Note the OSGi bundle packaging. This will work fine for non-OSGi projects, and your project is ready to go when you start using OSGi.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.poc.jibx</groupId>
        <artifactId>test</artifactId>
        <version>0.0.1</version>
        <packaging>bundle</packaging>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jibx</groupId>
                    <artifactId>jibx-maven-plugin</artifactId>
                    <version>1.2.3</version>
    
                    <executions>
                        <execution>
                            <id>generate-java-code-from-schema</id>
                            <goals>
                                <goal>schema-codegen</goal>
                            </goals>
                            <configuration>
                                <schemaLocation>src/main/resources</schemaLocation>
                                <options>
                                    <package>com.poc.jibx</package>
                                </options>
                            </configuration>
                        </execution>
                        <execution>
                            <id>compile-binding</id>
                            <goals>
                                <goal>bind</goal>
                            </goals>
                            <configuration>
                                <schemaBindingDirectory>target/generated-sources</schemaBindingDirectory>
                                <includes>
                                    <include>binding.xml</include>
                                </includes>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <extensions>true</extensions>
                    <configuration>
                        <instructions>
                            <Include-Resource>META-INF/binding.xml=${basedir}/target/generated-sources/binding.xml</Include-Resource>
                            <Export-Package>com.poc.jibx.*;version=${project.version}</Export-Package>
                        </instructions>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
        <dependencies>
            <dependency>
                <groupId>org.jibx</groupId>
                <artifactId>jibx-run</artifactId>
                <version>1.2.3</version>
            </dependency>
            <dependency>
                <groupId>org.jibx</groupId>
                <artifactId>jibx-extras</artifactId>
                <version>1.2.3</version>
            </dependency>
        </dependencies>
    
    </project>
    

    Good luck!

    Don jibx-maven-plugin project contributor