---
title: "ant使用jdt compiler编译"
author: "swbssd"
date: "2011-09-06T08:46:46Z"
tags: []
categories: ["编程语言"]
slug: "ant-jdt-compiler"
draft: false
lastmod: "2011-09-06T16:55:20Z"
id: 1166252
url: "https://swbssd.iteye.com/blog/1166252"
---

使用javacc编译存在一些条件无法编译的情况，例如org.codehaus.jackson.annotate.JsonIgnore的注解@JsonIgnore  
这个时候可以使用eclipse的编译器jdt进行编译，以下方法：  
 &lt;!--在ant中添加property，使用eclipse jdt compiler编译--&gt;  
 &lt;property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/&gt;

使用jdt的时候需要注意的是，javac必须指定版本否则无法编译  
 &lt;!-- 如果指定了build.compiler使用eclipse jdt编译就必须指定版本--&gt;  
 &lt;javac  
  nowarn="on"  
  source="1.6"  
  target="1.6"  
  deprecation="true"  
  debug="true" encoding="UTF-8"  
  srcdir="${base.src.dir}"  
  destdir="${classes.dir}"  
  classpathref="lib.class.path" &gt;  
 &lt;/javac&gt;

把eclipse的jdt三个jar包放到ant\\lib下面去：

org.eclipse.jdt.compiler.tool\_1.0.100.v\_894\_R34x.jar

org.eclipse.jdt.core\_3.4.4.v\_894\_R34x.jar

org.eclipse.jdt.debug.ui\_3.3.1.v20080730\_r341.jar

\----------------------------------------------------------------------------------

Class not found: org.eclipse.jdt.core.JDTCompilerAdapter 错误处理：  
ant调用eclipse的jdt出现这个错误，检查类名书写是否正确，是否有空格。   
&lt;property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/&gt;