2011-10-04 5 views
2

XML-Java 데이터 바인딩에 JiBX를 사용하고 있습니다. 현재 구성은 클래스를 꽤 잘 생성하지만, 생성 된 클래스가 java.io.Serializable을 구현하기를 원합니다.데이터 모델 클래스를 직렬화 가능하게 만들기

주어진 스키마에서 자바 클래스를 생성하는 maven plugin 설정입니다.

<plugin> 
    <groupId>org.jibx</groupId> 
    <artifactId>jibx-maven-plugin</artifactId> 
    <version>1.2.3</version> 
    <configuration> 
     <schemaLocation>src/main/resources</schemaLocation>    
     <includeSchemas> 
      <includeSchema>FS_OTA_VehResRS.xsd</includeSchema> 
     </includeSchemas> 
     <options> 
      <package>com.test.cars.model.ota2009a.vehresrs</package> 
     </options> 
     <schemaBindingDirectory>src/main/java</schemaBindingDirectory> 
     <includeSchemaBindings> 
      <includeSchemaBinding>*_binding.xml</includeSchemaBinding> 
     </includeSchemaBindings> 
    </configuration> 
    <executions>    
     <execution> 
     <id>generate-java-code-from-schema</id> 
     <goals> 
      <goal>schema-codegen</goal> 
     </goals> 
     </execution> 
     <execution> 
     <id>compile-the-binding-</id> 
     <goals> 
      <goal>bind</goal> 
     </goals> 
     </execution>    
    </executions> 
</plugin> 

This link 생성 된 모든 클래스를 java.io.Serializable을 구현하기 위해 org.jibx.schema.codegen.extend.SerializableDecorator를 사용하는 제안. 하지만 커스텀 화 파일을 작성하고 jibx-maven-plugin을 설정하는 방법을 모르겠습니다.

누구든지이 목표를 달성 할 수 있습니까?

답변

3

나는 그것을 얻을 수있다.

src/main/resources/schema-customizations.xml을 만들었습니다. 이 사용자 정의 설정 파일의 내용은 다음과 같습니다

<schema-set xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <class-decorator class="org.jibx.schema.codegen.extend.SerializableDecorator"/> 
</schema-set> 

또한 수정의 pom.xml이 <configuration>

<customizations> 
    <customization>src/main/resources/schema-customizations.xml</customization> 
</customizations> 

에서 사용자 정의 구성에 추가하고 mvn jibx:schema-codegen

이제 생성 된 모든 클래스가 java.io.Serializable

를 구현하고 실행

감사합니다. @SB

+0

serial-version 속성을 class-decorator 요소에 추가하도록 선택할 수도 있습니다.