前言
http+xml服务器开发时,由于没玩过ant,创建的maven项目,jibx操作起来各种阻碍
本篇不写其他一大堆文章写的命令行,就在idea里傻瓜式的完成这一项操作
别在这玩意身上耗费太多时间,以免错过后边无限好的风景。哪天有需要了再看
一、操作步骤
1.下载JiBX
目前最新版是 1.3.3 JiBX下载链接 :https://jibx.sourceforge.io/
下载完解压,环境变量看心情配不配都可。
这里我选择不配,这玩意以后使用频率还有待琢磨,直接写死就好了
2.项目根目录创建build.xml
build.xml 如下:
<?xml version="1.0" encoding="utf-8"?>
<project default="main" basedir=".">
<property environment="env"/>
<condition property="jibx-home" value="[这里替换为你jibx的地址,如果你配了环境变量,可以在env里取]\jibx_1_3_3\jibx">
<and>
<not>
<isset property="jibx-home"/>
</not>
<available file="[这里替换为你jibx的地址]\jibx_1_3_3\jibx\lib"/>
</and>
</condition>
<!-- End of jibx-home location setting block. -->
<!-- make sure required jars are present -->
<condition property="runtime-jars-found">
<available file="${jibx-home}/lib/jibx-run.jar"/>
</condition>
<condition property="binding-jars-found">
<and>
<available file="${jibx-home}/lib/bcel.jar"/>
<available file="${jibx-home}/lib/jibx-bind.jar"/>
<available file="${jibx-home}/lib/jibx-run.jar"/>
</and>
</condition>
<available property="extras-jar-found" file="${jibx-home}/lib/jibx-extras.jar"/>
<!-- set classpath for compiling and running application with JiBX -->
<path id="classpath">
<dirset dir="${basedir}/target/classes"/>
<fileset dir="${jibx-home}/lib" includes="*.jar"/>
<pathelement location="bin"/>
</path>
<target name="main" depends="compile,binding,bind" description="Main target"/>
<target name="compile" description="Compilation target">
<echo>Building file.</echo>
<javac srcdir="${basedir}/src/main/java" destdir="${basedir}/target/classes" includeantruntime="true"/>
</target>
<target name="binding">
<echo message="Running BindGen tool"/>
<java classpathref="classpath" fork="true" failonerror="true" classname="org.jibx.binding.generator.BindGen">
<arg value="你Order类的全限定名称"/>
</java>
</target>
<target name="bind">
<echo message="Running bind"/>
<taskdef name="bind" classname="org.jibx.binding.ant.CompileTask">
<classpath refid="classpath"/>
</taskdef>
<bind binding="${basedir}/binding.xml">
<classpath refid="classpath"/>
</bind>
</target>
</project>
3. 添加build.xml为Ant文件
右键 添加为Ant文件,让idea的Ant插件可以识别build.xml
然后在Ant窗口执行 main 这个 target 就会生成你需要的
至此TestOrder顺利执行,后边也就没啥问题了
总结
- 把项目依赖的JiBX相关版本改为1.3.3
- 下载JiBX 1.3.3
- 创建build.xml 配置 jibx路径 和 要生成的bean
- 生成xml和xsd ,以及classes里相关的字节码
- 完成