ant根据不同的os操作系统执行不同的命令
2013-05-23 10:49
218 查看
问题引出,ant的编译脚本,同时编译出windows和linux两个版本,脚本中的一段如下,该部分windows下完全通过,linux下failed。
<target name="xjc">
<java dir="${j3rdparty.extern.dir}" jar="${j3rdparty.extern.dir}\jaxb-xjc-annox.jar" failonerror="true" fork="true">
<arg value="-cp" />
<arg value="${j3rdparty.extern.dir}\jaxb2-basics-annotate-0.6.3.jar;${j3rdparty.extern.dir}\annox-0.5.1.jar;${j3rdparty.extern.dir}\jaxb2-basics-tools-0.6.3.jar;${j3rdparty.extern.dir}/commons-logging-1.1.1.jar;${j3rdparty.extern.dir}/commons-lang-2.4.jar;${bin.dir}"
/>
<arg value="-extension" />
<arg value="-Xannotate" />
<arg value="-d" />
<arg value="${src.dir}" />
<arg value="-p" />
<arg value="tellabs.inmfwk.tool.snod.xsd.${xsdname}" />
<arg value="${schema.dir}/${xsdname}.xsd" />
</java>
</target>
直接原因2个,一是linux下,分隔符用"/",而不是"\";而是linux下classpath的分隔符是冒号“:”而不是分号";"。
修改直接方案:将-cp参数,写成<path id="class.path" />,然后用classpathref在java中引用,但是不用java -jar,而是用java + MainClassName。
比较有趣的是,still not work。
有如下的exception:
"
Using java.util.ServiceLoader
Exception in thread "main"java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Providerorg.jvnet.jaxb2_commons.plugin.annotate.AnnotatePlu
gin could not be instantiated: java.lang.ClassCastException
atjava.util.ServiceLoader.fail(ServiceLoader.java:207)
atjava.util.ServiceLoader.access$100(ServiceLoader.java:164)
atjava.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:353)
atjava.util.ServiceLoader$1.next(ServiceLoader.java:421)
atcom.sun.tools.xjc.Options.findServices(Options.java:952)
atcom.sun.tools.xjc.Options.getAllPlugins(Options.java:374)
atcom.sun.tools.xjc.Options.parseArgument(Options.java:692)
atcom.sun.tools.xjc.Driver$OptionsEx.parseArgument(Driver.java:500)
atcom.sun.tools.xjc.Options.parseArguments(Options.java:802)
at com.sun.tools.xjc.Driver.run(Driver.java:239)
atcom.sun.tools.xjc.Driver.run(Driver.java:199)
atcom.sun.tools.xjc.Driver._main(Driver.java:122)
atcom.sun.tools.xjc.Driver.access$000(Driver.java:79)
atcom.sun.tools.xjc.Driver$1.run(Driver.java:102)
Caused by: java.lang.ClassCastException
atjava.lang.Class.cast(Class.java:2990)
atjava.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:345)
... 11 more
"
没办法,只能在ant中区分linux和windows。
方法如下:
<condition property="compile.on.windows">
<os family="windows" />
</condition>
然后针对windos和linux写不同的脚本,调用时:
<antcall target="xjc.classes.on.windows" />
<antcall target="xjc.classes.on.linux" />
OK,至此问题解决。
<target name="xjc">
<java dir="${j3rdparty.extern.dir}" jar="${j3rdparty.extern.dir}\jaxb-xjc-annox.jar" failonerror="true" fork="true">
<arg value="-cp" />
<arg value="${j3rdparty.extern.dir}\jaxb2-basics-annotate-0.6.3.jar;${j3rdparty.extern.dir}\annox-0.5.1.jar;${j3rdparty.extern.dir}\jaxb2-basics-tools-0.6.3.jar;${j3rdparty.extern.dir}/commons-logging-1.1.1.jar;${j3rdparty.extern.dir}/commons-lang-2.4.jar;${bin.dir}"
/>
<arg value="-extension" />
<arg value="-Xannotate" />
<arg value="-d" />
<arg value="${src.dir}" />
<arg value="-p" />
<arg value="tellabs.inmfwk.tool.snod.xsd.${xsdname}" />
<arg value="${schema.dir}/${xsdname}.xsd" />
</java>
</target>
直接原因2个,一是linux下,分隔符用"/",而不是"\";而是linux下classpath的分隔符是冒号“:”而不是分号";"。
修改直接方案:将-cp参数,写成<path id="class.path" />,然后用classpathref在java中引用,但是不用java -jar,而是用java + MainClassName。
比较有趣的是,still not work。
有如下的exception:
"
Using java.util.ServiceLoader
Exception in thread "main"java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Providerorg.jvnet.jaxb2_commons.plugin.annotate.AnnotatePlu
gin could not be instantiated: java.lang.ClassCastException
atjava.util.ServiceLoader.fail(ServiceLoader.java:207)
atjava.util.ServiceLoader.access$100(ServiceLoader.java:164)
atjava.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:353)
atjava.util.ServiceLoader$1.next(ServiceLoader.java:421)
atcom.sun.tools.xjc.Options.findServices(Options.java:952)
atcom.sun.tools.xjc.Options.getAllPlugins(Options.java:374)
atcom.sun.tools.xjc.Options.parseArgument(Options.java:692)
atcom.sun.tools.xjc.Driver$OptionsEx.parseArgument(Driver.java:500)
atcom.sun.tools.xjc.Options.parseArguments(Options.java:802)
at com.sun.tools.xjc.Driver.run(Driver.java:239)
atcom.sun.tools.xjc.Driver.run(Driver.java:199)
atcom.sun.tools.xjc.Driver._main(Driver.java:122)
atcom.sun.tools.xjc.Driver.access$000(Driver.java:79)
atcom.sun.tools.xjc.Driver$1.run(Driver.java:102)
Caused by: java.lang.ClassCastException
atjava.lang.Class.cast(Class.java:2990)
atjava.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:345)
... 11 more
"
没办法,只能在ant中区分linux和windows。
方法如下:
<condition property="compile.on.windows">
<os family="windows" />
</condition>
然后针对windos和linux写不同的脚本,调用时:
<antcall target="xjc.classes.on.windows" />
<antcall target="xjc.classes.on.linux" />
OK,至此问题解决。
相关文章推荐
- ANT 脚本根据windows 和linux操作系统的不同,自动采用不同的编译方式
- Java 根据环境属性区分不同操作系统
- 说说 Java I/O 系统——如何执行操作系统的命令
- Java /Jsp 执行操作系统命令 windows/Linux
- 存储过程中如何根据参数是否为空执行不同的select??
- 【转】ant学习笔记之(ant执行命令的详细参数和Ant自带的系统属性)
- Ubuntu里shell和命令执行结果不同(Bash和sh区别)
- Python执行系统命令的方法 os.system(),os.popen(),commands
- saltstack根据不同操作系统版本同步不同文件
- DOS批处理命令判断操作系统版本、执行各版本对应语句
- 浏览器兼容(根据不同的浏览器执行不同的代码)
- [整理修改] DOS 批处理命令判断操作系统版本 执行各版本对应语句
- 在SQLPlus中执行操作系统命令
- Python执行系统命令的方法 os.system(),os.popen(),commands
- [Ant自动打包]ant执行命令的详细参数和Ant自带的系统属性
- 操作系统 - 对于不同进程中指令的交替执行不要做任何假设
- 使用gitlab, jenkins搭建CI(持续集成)系统(3) -- 根据不同触发条件执行不同的构建任务
- Java /Jsp 执行操作系统命令 windows/Linux
- python执行系统命令的方法:os.system(), os.popen(), subprocess.Popen()
- ant学习笔记之(ant执行命令的详细参数和Ant自带的系统属性)