【问题标题】:jibx-maven-plugin 1.2.3 schema-codegen goal <schemaLocation> value ignoredjibx-maven-plugin 1.2.3 schema-codegen 目标 <schemaLocation> 值被忽略
【发布时间】:2011-09-22 14:54:16
【问题描述】:

我正在尝试使用 jibx-maven 插件 1.2.3 从 Schema 文件生成 Java 源代码。

以下是我的 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>

当我尝试使用命令运行目标时:mvn jibx:schema-codegen

我得到以下输出

[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] ------------------------------------------------------------------------

从输出中可以看出,正在搜索默认架构位置,即 src/main/config 而不是我配置的位置 src/main/resources

我遇到了以下 JIRA,它说上述插件配置是合适的,应该可以正常工作。 http://jira.codehaus.org/browse/JIBX-450

但是在我的情况下它不起作用。我是否缺少其他任何东西来完成这项工作?

谢谢,
吉格尼什

【问题讨论】:

  • 首先我建议尝试将架构定位到您已经尝试过的 src/main/config 中...您的架构名称是 *.xsd 吗?

标签: maven-plugin jibx


【解决方案1】:

吉格尼什,

实际上,您的第一个 pom 应该可以正常工作。 khmarbaise 是正确的,将架构定义放在 /src/main/config 目录中并确保它们具有 .xsd 扩展名被认为是一种好习惯。

这是一个更正的项目文件。我正在使用您的架构位置。请注意 OSGi 捆绑包打包。这对于非 OSGi 项目可以正常工作,并且当您开始使用 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>

祝你好运!

唐 jibx-maven-plugin 项目贡献者

【讨论】:

    【解决方案2】:

    问题已解决,我在此处发布解决方案,以便其他人遇到此问题时可以帮助他们:

    正确的 pom.xml 应该如下所示

        <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>
    

    在我的第一篇文章中,plugin 部分显示了 execution 元素内的 configuration 部分,而在上面的代码中,它位于 之外处决

    我之前使用的代码 sn-p 来自http://jibx.sourceforge.net/maven-jibx-plugin/schema-codegen.html 显示的示例用法示例

    在部分下

    从架构生成 Java 源代码并编译绑定

    来自 XSD 架构的 Java 源代码

    下面是一个示例用法

    我认为这是错误的,需要纠正。

    正确的代码 sn-p 可在部分

    下找到

    从架构生成 Java 源代码

    来自 XSD 架构的 Java 源代码

    这是一个示例插件部分

    谢谢,
    吉格尼什

    【讨论】:

      猜你喜欢
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      • 2021-04-26
      • 1970-01-01
      • 2014-07-17
      • 2020-08-30
      • 1970-01-01
      相关资源
      最近更新 更多