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&开发者_高级运维lt;/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,
JigneshJignesh,
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
The issue is resolved and I am posting the solution here so that it can help others, if they face this issue:
The correct pom.xml should look like below
<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>jibx-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jibx-sample</name>
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<schemaLocation>src/main/conf</schemaLocation>
<includeSchemas>
<includeSchema><YOUR_SCHEMA_FILE_NAME>.xsd</includeSchema>
</includeSchemas>
<options>
<package>com.poc.jibx</package>
</options>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
</configuration>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<goals>
<goal>schema-codegen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
In my first post the plugin section shows the configuration section inside the execution element while in the above code it is outside executions
The code snippet I used earlier I took from the sample usage example shown at http://jibx.sourceforge.net/maven-jibx-plugin/schema-codegen.html
under section
Generate Java Sources from Schemas and Compile Binding
Java Sources from XSD Schemas
Here is below a sample usage:
which I suppose is wrong and needs rectification.
The correct code snippet is available under section
Generate Java Sources from Schemas
Java Sources from XSD Schemas
Here is a sample plugin section:
Thanks,
Jignesh
精彩评论