I use Eclipse Mars to compile a project. My understanding is that Eclipse is using it's own Java compiler (JDT) to compile Java code.
How can I find out the version of the Eclipse compiler so that I can tell other people what version I am using?
I use Eclipse Mars to compile a project. My understanding is that Eclipse is using it's own Java compiler (JDT) to compile Java code.
How can I find out the version of the Eclipse compiler so that I can tell other people what version I am using?
There isn't really a separate version for the ECJ compiler.
The standalone download of ECJ available on the Eclipse Project page is just numbered to match the Eclipse release (so 4.6 for the current Eclipse Neon release).
The compiler itself is included in the org.eclipse.jdt.core
plugin which has its own version (currently 3.12.0)
I refer you to:
1: How to change JDK version for an Eclipse project
2: changing eclipse's java compiler to jdk7
3: how do I get eclipse to use a different compiler version for Java?
You need to first go into Java EE Perspective. For this go to the ribbon and then: Window > Perspective > Open Perspective > Other > Java EE.
NB: If you don't see this then it means you don't have the Java EE perspective installed: See how to download it here:
How to add Java EE perspective to Eclipse
After that, open the Package Explorer. Then right click on your Java Project and select Properties. In the properties window, there should be an option for "Project Facets". This page lists the versions of all the Facets in your compiler. You can then see the version number for the Java Compiler as well.
If you need to change this, click Modify Project. Then, click the facet you want to change it too. Do this by selecting the version from the drop-down menu next to the Facet's name (Java Compiler). Click finish and then click OK.
Hope this helps!
Using command line for standalone ECJ:
java -jar ecj.jar -version
Examples:
With ECJ taken from https://mvnrepository.com/artifact/org.eclipse.jdt.core.compiler/ecj/4.6.1 :
...> java -jar ecj-4.6.1.jar -version
Eclipse Compiler for Java(TM) v20160829-0950, 3.12.1, Copyright IBM Corp 2000, 2015. All rights reserved.
With ECJ taken from http://archive.eclipse.org/eclipse/downloads/drops/R-3.8.2-201301310800/#JDTCORE :
...> java -jar ecj-3.8.2.jar -version
Eclipse Compiler for Java(TM) v20130121-145325, 3.8.3, Copyright IBM Corp 2000, 2012. All rights reserved.
(One should notice the difference between ECJ versions and published jar names.)
Do that programmatically using JSR-199 api:
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.ServiceLoader;
import javax.tools.JavaCompiler;
public class CompilerVersion {
public static void main(String[] args) throws Exception
{
// Standalone ECJ from http://repo1.maven.org/maven2/org/eclipse/jdt/ecj/3.13.50/ :
//jar2classpath("E:\\ecj-3.13.50.jar");
// Load JDT Core & Compiler jars from installed Eclipse Oxygen 4.7.0:
String eclipseDir = "D:\\eclipse\\";
jar2classpath(eclipseDir + "plugins\\org.eclipse.jdt.core_3.13.0.v20170516-1929.jar");
jar2classpath(eclipseDir + "plugins\\org.eclipse.jdt.compiler.tool_1.2.0.v20170502-0408.jar");
//Class.forName("org.eclipse.jdt.internal.compiler.tool.EclipseCompiler");
JavaCompiler compiler = ServiceLoader.load(JavaCompiler.class).iterator().next();
compiler.getTask(null, null, null,
Arrays.asList(new String[] {"-version"}), null, null).call();
}
private static void jar2classpath(String jarFilename) throws Exception {
File file = new File(jarFilename);
Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{file.toURI().toURL()});
}
}
Should output to stderr
:
Eclipse Compiler for Java(TM) v20170516-1929, 3.13.0, Copyright IBM Corp 2000, 2015. All rights reserved.