当前位置: 首页 > 工具软件 > JiBX > 使用案例 >

java jibx,Maven自动绑定JiBX配置

怀晋
2023-12-01

1) 首先,要写bind.xml和schema。不过还好,官方有提高工具类可以用。

org.jibx.binding.generator.BindGen或org.jibx.binding.BindingGenerator这两个类都可以,用法如下:

首先用dos进入当前工程目录,然后执行命令:E:\Study\WebHttpUtils>java -cp

bin;lib/jibx-tools.jar;lib/log4j-1.2.16.jar

org.jibx.binding.generator.BindGen -b bind.xml

com.hoo.entity.Account

上面的java 是运行某个程序 –cp是依赖的classpath路径的jar、zip等文件,-b

是输出文件名称,是BindGen类的参数。这样会在当前工程目录中生成bind.xml和entity.xsd文件。先看看这2个文件

bind.xml

< ?xml version="1.0" encoding="UTF-8"? >

< mapping class="com.hoo.entity.Account" name="account" >

< value style="element" name="name" field="name" usage="optional" />

< value style="element" name="address" field="address" usage="optional" />

< structure field="birthday" usage="optional" name="birthday" >

< value style="element" name="birthday" field="birthday" usage="optional" />

< /mapping>

< /binding>entity.xsd文件

< xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://hoo.com/entity"elementFormDefault="qualified" targetNamespace="http://hoo.com/entity" >

< xs:element type="tns:account" name="account" /> < xs:complexType name="account"> < xs:sequence> < xs:element type="xs:string" name="name" minOccurs="0" />

< xs:element type="xs:string" name="email" minOccurs="0" /> < xs:element name="birthday" minOccurs="0">

< xs:complexType > < xs:sequence> < xs:element type="xs:string" name="birthday" minOccurs="0" /> < /xs:sequence> < /xs:complexType> < /xs:element > < /xs:sequence> < xs:attribute type="xs:int" use="required" name="id" /> < /xs:complexType >< /xs:schema>

参考:http://www.cnblogs.com/hoojo/archive/2011/04/27/2030205.html

2)配置pom(没找到中文的)

To use the 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.6< /version >

< executions >

< execution >

< goals >

< goal >bind< /goal >

< /goals >

< /execution >

< /executions >

< /plugin >

The project also needs to include jibx-run and optionally

jibx-extras in its dependencies.

< dependency >

< groupId >org.jibx< /groupId >

< artifactId >jibx-run< /artifactId >

< version >1.2.6< /version >

< /dependency >

< dependency >

< groupId >org.jibx< /groupId >

< artifactId >jibx-extras< /artifactId >

< version >1.2.6< /version >

< /dependency >

The plugin supports the following configuration options.

option

default

description

schemaBindingDirectory

src/main/config

In which directory to search for binding

definitions.

includeschemaBindings

binding.xml

Which files in the configuration directory to

include as binding definitions.

excludeschemaBindings

none

Which files in the configuration directory that

will be matched by one the include patterns to exclude.

multi-module

false

Control flag to enable multi-module mode. (See

modes.html#Multi-module mode)

modules

none

Which modules to include in multi-module mode.

(See modes.html#Restricted multi-module mode)

load

false

Control flag for test loading generated/modified

classes.

validate

true

Control flag for binding definition

validation.

verbose

false

Control flag for verbose processing reports.

verify

false

Control flag for verifying generated/modified

classes with BCEL.

This example would include all files ending in

-binding.xml except template-binding.xml in the

src/main/jibx directory and output verbose messages during

binding compilation:

< plugin >

< groupId >org.jibx< /groupId >

< artifactId >jibx-maven-plugin< /artifactId >

< version >1.2.6< /version >

< configuration >

< schemaBindingDirectory >src/main/jibx< /schemaBindingDirectory >

< includeSchemaBindings >

< includeSchemaBindings >*-binding.xml< /includeSchemaBindings >

< /includeSchemaBindings >

< excludeSchemaBindings >

< excludeSchemaBinding >template-binding.xml< /excludeSchemaBinding >

< /excludeSchemaBindings >

< verbose >true< /verbose >

< /configuration >

< executions >

< execution >

< goals >

< goal >bind< /goal >

< /goals >

< /execution >

< /executions >

< /plugin >

3) jibx:bind

参考:http://jibx.sourceforge.net/maven-jibx-plugin/

 类似资料: