无法访问类的绑定信息

时间:2014-05-08 10:07:19

标签: java maven jibx

我知道这个问题一再被问到,而且它总是一个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但是由于某种原因没有运行绑定?

1 个答案:

答案 0 :(得分:0)

需要添加另一个指向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>