51

I installed JDK 7 and Eclipse 3.6M6. Then, I added JRE 7 as a new JRE execution environment in Eclipse, and set the compiler compliance level to Java 7. I can compile the following piece of code through command line using the javac that comes with JDK 7.

import java.util.HashMap; import java.util.Map; public class Try { public static void main(String[] args) { Map<Integer, String> map = new HashMap<>(); } } 

But, Eclipse gives the following error messages.

Incorrect number of arguments for type HashMap; it cannot be parameterized with arguments Try.java /TryJava7/src line 7 Java Problem

Syntax error on token "<", ? expected after this token Try.java /TryJava7/src line 7 Java Problem

Even though I've set the compliance level of the compiler to Java 7, it looks like Eclipse doesn't understand Java7 syntax yet. Is it possible to play with Java 7 in Eclipse?

The following is the content of .classpath.

<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="output" path="bin"/> </classpath> 

And, the following is the content of .settings/org.eclipse.jdt.core.prefs.

eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.7 
2
  • @Oscar Reyes, I don't think Java 7 specification for closures has been published officially yet. Commented May 23, 2010 at 15:48
  • 5
    @Oscar Closures are scheduled for jdk8 Commented Feb 25, 2011 at 0:11

6 Answers 6

40

As Alex pointed out, Eclipse uses its own compiler which currently doesn't support Java 7 and, as noted in the Project Plan For Eclipse Project, version Helios, support for Java 7 is deferred and decoupled from the 3.6 release:

  • ((new) deferred) Add support for Java SE 7 features. The next feature release of Java SE is version 7, which will probably be available in the second half of 2010. While the contents of this release are still under discussion, that release is expected to contain extensions to the Java language, including annotations on types (JSR-308), modularity support (JSR-294), and other minor language changes (Coin project). Eclipse Java tooling will include initial support for compiling, editing, and launching applications for Java 7 for those parts which have publicly available specifications (only JSR-308 at this point). [JDT Core, JDT UI] (288548)

    NOTE: In order to align our schedule with the delayed official Java 7 appearance and due to lack of publicly available specifications (including lack of a Java 7 JSR), we have decided to move the development work to a separate branch and decouple it from the 3.6 release. In that branch we will continue to develop the Java 7 features as they become publicly accessible. We will deliver separate updates for the official builds in order to provide early access to Java 7 features.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 for that image :) (and the remnant of the information of course)
Thanks for citing the Eclipse plans for supporting Java 7. They mention that they will support Java 7 in a different branch. Do you know where that branch of development is?
@reprogrammer Not really. The Eclipse repository is a bit too cryptic for me (dev.eclipse.org/viewcvs/index.cgi) and even the naming of branches is not clear (check the org.eclipse.jdt.core module for example). Maybe someone will be able to provide a better answer but my suggestion would be to ask on the Eclipse developer list.
18

See http://wiki.eclipse.org/JDT_Core/Java7, http://wiki.eclipse.org/PDE/API_Tools/Java7 and Bug 288548 for the ongoing support of Eclipse for Java 7. And see http://wiki.eclipse.org/JDT/Eclipse_Java_7_Support_%28BETA%29 for instructions on how to evaluate Java 7 in Eclipse.

UPDATE 1: The BETA_JAVA7 branch has been merged to HEAD and R3_7_maintenance (See the eclipse-dev archive).

UPDATE 2: Eclipse 3.7.1 (Indigo SR1) supports Java 7.

1 Comment

Nice links! Those are really helpful.
6

Eclipse has its own embedded Java compiler. So if there is no eclipse beta or something like that that already can compile Java 7 then you're out of luck.

Netbeans should work.

Comments

3

I checkout the so called JSR 308 branch of org.eclipse.jdt.core using the following CVS repository information.

Connection type: pserver User: anonymous Host: dev.eclipse.org Port: Default Repository path: /cvsroot/eclipse Module: org.eclipse.jdt.core Tag: JSR_308 (Branch) 

Then, I followed the instructions to install the checked out JDT in eclipse. Subsequently, I looked up org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java and /org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java to come up with small examples exercising JSR 308 type annotations.

At this point, the branch supports and generates the corresponding new attributes in the .class files when annotations on types are present. But, annotation processors don't seem to work.

Comments

2

Java 7 support (BETA) is now available in JDT. See http://thecoderlounge.blogspot.com/2011/06/java-7-support-in-eclipse-jdt-beta.html

Comments

0

14 years later, that support will be phased out with Eclipse 4.33 (Q3 2024):

Removed support for souce, target and release Java 7 and below

The following compiler options are now supported only for Java 8 and above:

--source --target --release 

I.e., from Eclipse 4.33 onward, the Eclipse IDE and ecj will no longer be able to produce JRE 7 (and below) compliant byte code, as the options metioned above are supported only for Java 8+. This is the equivalent of Java 21's javac only supporting those options for Java 8+.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.