java - Maven & Eclipse Mars编译java 1.8错误

标签 java eclipse maven

我用的是Eclipse

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

和 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"

我的 %JAVA_HOME% 设置为

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

我的 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)

我使用 -vm(java jdk 版本)运行 eclipse,并在 eclipse 中添加了外部 maven 安装。在我导入一个项目并出现奇怪的行为之后。有些类在 eclispe 中是红色的,有些则不是。我检查了 javap -version,它们都是用主要版本 52 编译的。我创建了新的工作区并得到了相同的结果。很奇怪。如果我用 eclipse 打开一个“红色”Java 类并保存它,它就会正常(没有编译错误)。

我真的不知道是什么问题。

我在 eclipse 中遇到的错误

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

作为父 pom,我使用版本为 1.3.3-RELEASE 的 spring-boot-starter-parent 我还指定了我知道的所有属性,如 java.version、maven.compiler.source/target 和项目构建源和输出编码。还尝试定义 Maven 编译器插件。没有帮助。

提供代码示例

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

它看起来完全依赖于我放入类的包。 对于某些包,它只是正常编译,对于某些包,它有以下错误

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

不同包中的完全相同的类不会产生该错误。只是在一个特定的包。有什么我可以检查的想法吗?

最佳答案

埋藏在某个地方的可能是一个导致所有其他错误的实际编译错误。专注于此。就我而言,我有一个文件缺少 } .我能够通过浏览整个 错误列表以查找不是Syntax error on token 的错误来找到该文件。或 foo cannot be resolved to a bar .

来自评论:

In my case, there was an unresolved conflict in another file. Apparently the eclipse-mars and/or java8 eclipse compiler fails to compile/build other files in a meaningful manner after some types of compile errors in dependent files, instead spouting what appears to be gibberish errors for the files that can't be built do to the bad dependency

(此答案基于 Richard Sitze 的评论,适用于将来发现此问题的任何其他人。)

关于java - Maven & Eclipse Mars编译java 1.8错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36581047/

相关文章:

java - 如何在Eclipse中调试外部插件?

scala - 自定义Maven插件上的分类器等效

java - 如何从根模块运行子模块中找到的应用程序?

java - visualvm 在带有 Oracle JDK 的 Ubuntu 15.10 上失败并显示 "No jdkhome found"

java - 树脂服务器错误

java - 带图片和文字的自定义按钮?

java - 如何解决 "java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.accessibleConstructor"

Java - getBounds2D,椭圆矩形碰撞

java - 不确定为什么我会收到此空指针异常错误

java - 为什么 'headlines.add(xpp.nextText());' 给我一个错误?