Maven & Eclipse Mars compiles java 1.8 errors

I am using eclipse

Version: Mars.2 Release (4.5.2) Build id: 20160218-0600 

and maven (mvn -v)

 Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:37+02:00) Maven home: C:\Daten\maven Java version: 1.8.0_60, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_60\jre Default locale: de_DE, platform encoding: Cp1252 OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos" 

my% JAVA_HOME% is set to

 C:\Program Files\Java\jdk1.8.0_60 

and my java (java -version)

 java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) 

I run eclipse with -vm (java jdk version) and I added an external maven installation in eclipse. after i imported the project and got the strang behavior. Some classes are red in eclispe, and some are not. I check with javap -version and they are all compiled with the main version 52. I created a new workspace and got the same result. very strange. If I open the β€œred” Java class with eclipse and just save it, it will become normal (without compilation errors).

I really don't know what the problem is.

Errors I get in eclipse

 Syntax error on token "package", assert expected Syntax error on token "import", throw expected 

as the parent pom I use spring-boot-starter-parent with version 1.3.3-RELEASE I also specified all the properties that I know as java.version, maven.compiler.source / target and the project build source and output encoding. also tried to define the maven compiler plugin. did not help.

containing sample code

 package com.test; public class AExample { public static void main(String[] args) { System.out.println(args.length); } } 

it looks like it is completely dependent on the package in which I put the class. with some package it simply compiles, as usual, with some it has the following erros

 com.test cannot be resolved to a type AExample.java line 1 Illegal modifier for the local class AExample; only abstract or final is permitted AExample.java line 3 Syntax error on token "package", assert expected AExample.java line 1 Syntax error, insert "ClassBody" to complete ClassDeclaration AExample.java line 3 The nested type AExample cannot hide an enclosing type AExample.java line 3 

the same class in another package did not cause this error. only in a specific package. Any ideas what I can check?

+8
java eclipse maven
source share
1 answer

Buried somewhere is probably the only actual compilation error that causes everyone else. Focus on that. In my case, I had a file without } . I managed to find the file by dividing the entire list of errors into errors that were not Syntax error on token or foo cannot be resolved to a bar .

From the comments:

In my case, an unresolved conflict occurred in another file. Apparently, the eclipse-mars compiler and / or java8 eclipse cannot compile / create other files in a meaningful way after some types of compilation errors in dependent files, instead exhausting what seems like gibberish errors for files that cannot be built. to bad addiction

(This answer is based on a comment by Richard Prints, for anyone who finds this question in the future.)

+5
source share

All Articles