【问题标题】:Unable to access binding information for class无法访问类的绑定信息
【发布时间】:2014-05-08 10:07:19
【问题描述】:

我知道这个问题已经被问了一遍又一遍,而且它总是一个 Eclipse Maven JIXB 问题。我认为它从未得到解决。

当我尝试测试我的代码时,我收到以下错误

Unable to access binding information for class com.generated.xml.addbooking.Request
Make sure the binding has been compiled
java.lang.NoSuchFieldException: JiBX_bindingList
    at java.lang.Class.getDeclaredField(Class.java:1882)
    at org.jibx.runtime.BindingDirectory.getBindingList(BindingDirectory.java:68)

现在我已经生成了 POJO,并使用以下 POM 生成了 binding.xml 文件。

<plugin>
  <groupId>org.jibx</groupId>
  <artifactId>jibx-maven-plugin</artifactId>
  <version>1.2.5</version>
  <executions>
    <execution>
      <id>schemata-a</id>
      <goals>
        <goal>schema-codegen</goal>
      </goals>
      <configuration>
        <schemaLocation>src/main/resources/schemas</schemaLocation>
        <includeSchemas>
          <includeSchema>AddBookingRequest.xsd</includeSchema>
        </includeSchemas>
        <schemaBindingDirectory>src/main/java</schemaBindingDirectory>
        <includeSchemaBindings>
          <includeSchemaBindings>binding.xml</includeSchemaBindings>
        </includeSchemaBindings>
        <options>
          <package>com.generated.xml.addbooking</package>
        </options>
      </configuration>
    </execution>
    <execution>
      <id>schemata-b</id>
      <goals>
        <goal>schema-codegen</goal>
      </goals>
      <configuration>
        <schemaLocation>src/main/resources/schemas</schemaLocation>
        <includeSchemas>
          <includeSchema>SearchHotelPriceRequest.xsd</includeSchema>
        </includeSchemas>
        <schemaBindingDirectory>src/main/java</schemaBindingDirectory>
        <includeSchemaBindings>
          <includeSchemaBindings>binding.xml</includeSchemaBindings>
        </includeSchemaBindings>
        <options>
          <package>com.generated.xml.searchhotel</package>
        </options>
      </configuration>
    </execution>
    <execution>
      <id>compile-binding</id>
      <goals>
        <goal>bind</goal>
      </goals>
      <configuration>
        <schemaBindingDirectory>src/main/java</schemaBindingDirectory>
        <includes>
          <include>binding.xml</include>
        </includes>
      </configuration>
    </execution>
  </executions>
</plugin>

您可以看到 POJO 已生成,binding.xml 已生成,但由于某种原因绑定没有运行?

【问题讨论】:

  • 需要添加另一个插件以确保 maven 编译为 1.5 或更高版本,因为绑定使用泛型。

标签: java maven jibx


【解决方案1】:

出于某种原因,需要添加另一个指向 1.5 或更高版本的插件,maven 2 插件正在针对 1.3 进行编译。导致使用泛型的绑定问题。

我在我的插件中添加了以下内容

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument></compilerArgument>
                </configuration>
            </plugin>

【讨论】:

    猜你喜欢
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多