It turns out that there is a difference because Eclipse uses its own Java compiler!
I discovered this interesting little problem while I was using Ant for compilation (using the Java JDK compiler). Some code that worked perfectly well on Eclipse IDE failed to work when the program was compiled using the JDK version.
How to configure Ant to use a different Java compiler
The following would probably work wherever Java is installed and running properly, as you will be using jars. These have been tested and verified using Windows and Mac:
1. Download ecj.jar and jdtCompilerAdapter.jar
a. ecj.jar - Eclipse Java compiler and Ant plug-in
b. jdtCompilerAdapter.jar - JDT core Adapter*
*The JDT Core component is an incremental Java compiler. Thus, it allows to run and debug code which still contains unresolved compile errors. This is a major difference between the Eclipse compiler and the Java JDK compiler, which comes in handy especially when developing modularized components.
Note: If you already have Eclipse installed, try searching for these 2 jars from the directory where Eclipse is installed.
2. Look for your Ant installation directory and copy ecj.jar and jdtCompilerAdapter.jar to its lib/ directory:
a. For Windows, look for your
b. For Mac, go to /usr/share/ant/lib (Or try locating Ant by typing 'locate ant/lib' on your Mac Terminal)
3. In order for your Ant project to use the Eclipse Java compiler, you will have to change the Ant javac task's compiler attribute on your project's build.xml:
<target name="compile">
<javac srcdir="${srcdir}" destdir="${destdir}"
classpathref="${classpathref}"
compiler="org.eclipse.jdt.core.JDTCompilerAdapter"
source="1.6"
target="1.6"/>
</target>
After running 'ant compile' on your Windows command line or Mac Terminal, your Ant project should now be able to use the Eclipse Java compiler. If you would like your project to go back to using the JDK compiler, simply remove the compiler attribute from the javac task, and it should use the default (i.e. JDK) compiler once again.