Follow My Heart: Why ANT terminates in Eclipse

## 2011年10月20日星期四

### Why ANT terminates in Eclipse

It is very convenient to use ANT to compile our projects in Eclipse.
Also Eclipse has already integrated ANT, so users do not need to install ANT independently.

But sometimes, ANT will surprisingly terminates during Compiling process.

The reason is that ANT use UTF-8 as default encoding pattern.
But Java JDK/JRE will print out Locale Error and Warning Message during COMPILING process.

So sometimes, Eclipse integrated ANT cannot deal with the error/warning feedback correctly. The underground program throws "Runtime Exception", which lead ANT be unexpectedly Terminated.

There are two simple solutions.

1. use CMD rather than Eclipse (ANT Plugin) to run ANT. Download independent ant, deploy it in your local environment, finish path configuration and then run it through command line mode. Now you can see what error/warning message happened.
2. Add parameters when you run ANT in Eclipse.  I forget the specific name of parameter. I remember that it redirects all error and warning message to normal system.out. Now you can also see the error message, though not in RED format.

#### 1 条评论:

1. I found some valuable source in the Internet. So now Let's have a look at the solution:

1, unify the JRE/JDK of ANT and Eclipse.
[Description] The most common reason for "ANT STOPS in ECLIPSE" is that you have defined more than 1 JRE in your current workspace.
[SOLUTION] click your build.xml, choose [Run Configuration], and then open [JRE] tag, choose [Runtime JRE] as "Run in the same JRE as the worksapce". Then your problem is gone!

2, Some times ANT stops because it cannot find correct encoding for output result/warning/errors.
[Solution] So you can edit your project's encoding to certain encoding type, such as "MS932", "UTF-8", or "Windows31J" , ...
[Note] This problem is very common when you want to make javadoc by ANT. So you have another choice. That is, add "additionalparam="-J-Dfile.encoding=UTF-8"" into your "javadoc" target, and explicitly specify which kind of encoding your want.