您的位置:首页 > 其它

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,至此问题解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: