如何连接code以UTF-8 Java文件采用Apache Ant? [英] How to encode Java files in UTF-8 using Apache Ant?
问题描述
在我的build.xml文件由我取CXF一些Java文件。一些Java文件必须在恩UTF-8 codeD。如何使用Ant来更改编码为UTF-8?
In my build.xml file I fetch some Java files by cxf. Some of these Java files need to be encoded in UTF-8. How can I use Ant to change the encoding to UTF-8?
PS:我找到了如何设置的javac为UTF-8编码的指令,但在此之前的javac我需要Java文件是在UTF-8。否则,我得到一个错误:
PS: I found instructions for how to set the encoding for javac to UTF-8, but prior to javac I need Java files to be in UTF-8. Otherwise I get an error:
警告:不可映射字符编码UTF-8
warning: unmappable character for encoding utf-8
下面是我的code:
<macrodef name="lpwservice">
<attribute name="name"/>
<attribute name="package"/>
<sequential>
<property name="wsdlfile" value="${portal.basedir}/lpw/wsdl/@{name}.wsdl"/>
<mkdir dir="${portal.basedir}/lpw/wsdl"/>
<get src="${lpw.baseuri.cxf}/@{name}?wsdl" dest="${portal.basedir}/lpw/wsdl/@{name}.wsdl.new"/>
<if>
<and>
<filesmatch file1="${portal.basedir}/lpw/wsdl/@{name}.wsdl" file2="${portal.basedir}/lpw/wsdl/@{name}.wsdl.new"/>
<uptodate targetfile="${portal.basedir}/lpw-wsdl.jar" srcfile="${portal.basedir}/lpw/wsdl/@{name}.wsdl"/>
</and>
<then>
<echo message="${wsdlfile} is up to date" level="info"/>
<delete file="${portal.basedir}/lpw/wsdl/@{name}.wsdl.new"/>
</then>
<else>
<echo message="${portal.basedir}/lpw/wsdl/@{name}.wsdl needs update" level="info"/>
<move file="${portal.basedir}/lpw/wsdl/@{name}.wsdl.new" tofile="${portal.basedir}/lpw/wsdl/@{name}.wsdl" overwrite="true" />
<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true" failonerror="true">
<arg value="-client"/>
<arg value="-d"/>
<arg value="${portal.basedir}/lpw/src"/>
<arg value="${portal.basedir}/lpw/wsdl/@{name}.wsdl"/>
<classpath>
<path refid="cxf.classpath"/>
</classpath>
</java>
</else>
</if>
</sequential>
</macrodef>
我应该怎么做这里让
What should I do here to make
<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true" failonerror="true">
为en以UTF-8 code java文件?
to encode java files in utf-8?
推荐答案
Ant的 &LT;复制&GT;
任务有属性编码
和 outputencoding
。
<copy file="myJavaFile.java" tofile="myJavaFile.java" overwrite="true"
encoding="ISO-8859-1" outputencoding="UTF-8" />
所有的Java文件的目录
<property name="source.dir" location="/path/to/java/files" />
<copy todir="${source.dir}" overwrite="true"
encoding="ISO-8859-1" outputencoding="UTF-8">
<fileset dir="${source.dir}" includes="*.java" />
</copy>
只需更改 ISO-8859-1
到Java文件的编码格式。
Simply change ISO-8859-1
to the encoding format of your Java files.
这篇关于如何连接code以UTF-8 Java文件采用Apache Ant?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!