使用Ant編譯遇到的問題

  

一、ant安裝、配置後報錯:Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/tools/ant/launch/Launcher : Unsupported major.minor version 52.0  ……java

解決方案:ant下載最新版本1.10.1應該是1.8版本java編譯生成。下降重新下載ant 1.7.1版本,執行ant命令,運行正常。apache

二、ANT編譯錯誤: 編碼utf8的不可映射字符eclipse

  解決方案:ui

  使用eclispse的JDK進行編譯。修改build.xml文件,加上以下屬性:編碼

  <project basedir="." default="antwar_fjwan" name="carzone_ds">
      <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>spa

  同時javac添加jdk版本參數xml

  <javac nowarn="on" srcdir="${basedir}\src" destdir="${basedir}\WebContent\WEB-INF\classes" encoding="utf-8" source="1.7" target="1.7" includeantruntime="false">ip

  ant一下,會報找不到org.eclipse.jdt.core.JDTCompilerAdapterutf-8

      將eclipse/plugins目錄下把org.eclipse.jdt.*文件拷到ant/lib目錄下。以及org.eclispe.jdt.core_…….jar裏面的jdtCompilerAdapter.jar拷到ant/lib目錄下。而後從新編譯,一切OK。get

  

三、在上一個問題中個人jdtCompilerAdapter.jar是從網上直接下載的,編譯時有些文件會提示編譯錯誤:Cannot switch on a value of type String. Only convertible int values or enum constants are permitted。

  解決方案:因爲Ant編譯時的JDK版本爲1.6,可是如今應該使用1.7編譯致使的。將eclips/plugins目錄下org.eclispe.jdt.core_…….jar解壓取裏面的jdtCompilerAdapter.jar拷到ant/lib目錄下。而後從新編譯,一切OK。

相關文章
相關標籤/搜索