Java编译错误:Mac [英] Java compilation error: Mac

查看:120
本文介绍了Java编译错误:Mac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mavericks上安装了1.7 JDK的Eclipse上遇到了编译问题:

I had a compilation problem with Eclipse with 1.7 JDK installed running on Mavericks:

课程文件的版本51.0错误,应为49.0

因此,由于这看起来像javac版本控制问题,因此我删除了所有Java版本.安装了1.7_51,安装了Apple提供的1.6版本,以便运行Eclipse,更改了符号链接,因此默认值为1.7.与以前相同的问题,相同的项目无法编译,尽管其他项目可以编译

So, as this looked like a javac versioning problem I removed all java versions. Installed 1.7_51, installed the Apple supplied 1.6 version so that Eclipse would run, changed sym links so 1.7 was the default. Same problem as before, the same project would not compile, though others did,

下一步,将问题分解到裸露的骨头上,即从等式中删除ant等-使用的Test.java文件没有方法,只有System.out.println()是主要方法. cd到包含源文件的目录,并运行编译器并指定Javac的完整路径,并检查是否未设置JAVA_HOME:

Next step, strip the problem down to the bare bones i.e. remove ant etc from the equation - Test.java file used has no methods, just a main with System.out.println(). cd to the directory containing the source file and ran the compiler specifying full path to javac, having checked that JAVA_HOME was not set:

$ /图书馆/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/javac Test.java -verbose -extdirs. -endorseddirs. -cp. -bootclasspath /图书馆/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar 版本

$ /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/javac Test.java -verbose -extdirs . -endorseddirs . -cp . -bootclasspath /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar -version

输出:

javac 1.7.0_51

javac 1.7.0_51

[解析启动的Test.java]

[parsing started Test.java]

[解析完成67毫秒]

[parsing completed 67ms]

[源文件的搜索路径:[.]]

[search path for source files: [.]]

[类的搜索路径 文件:[/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar, .]]

[search path for class files:[/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar, .]]

[正在加载 /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)]

[loading /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)]

Test.java:11:无法访问java.lang.Object错误的类文件: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)

Test.java:11: cannot access java.lang.Object bad class file: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)

类文件的版本51.0错误,应为49.0

class file has wrong version 51.0, should be 49.0

请删除或确保它出现在以下位置的正确子目录中: 类路径.公开课测试{ ^

Please remove or make sure it appears in the correct subdirectory of the classpath. public class Test { ^

[总336ms] 1个错误

[total 336ms] 1 error

迷糊了.

有什么想法吗?

在相关说明中,我似乎无法使javac接受高于1.5/5的-target选项:

On a related note I seem to be unable to get javac to accept a -target option above 1.5/5:

$ /图书馆/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/javac Test.java -verbose -extdirs. -endorseddirs. -cp. -bootclasspath /图书馆/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar -version -target 1.7

$ /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/javac Test.java -verbose -extdirs . -endorseddirs . -cp . -bootclasspath /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar -version -target 1.7

导致:

javac 1.7.0_51

javac 1.7.0_51

javac:无效的目标版本:1.7

javac: invalid target release: 1.7

推荐答案

经过大量讨论后,发布了许多修复程序-所有这些都没有解决问题-我诉诸于使用dtrace来查看正在访问哪些文件由javac在命令运行时提供.

After much playing around with the numerous discussions fixes posted - all of which didn't do the trick - I resorted to using dtrace to see what files were being accessed by javac when the command was run.

在终端中(您需要安装XCode)

In terminal (you need XCode installed)

sudo dtrace -s /dev/stdin

syscall::open*:entry

{

   printf("%s %s", execname, copyinstr(arg0));

}

<Ctrl-D>

在另一个终端实例中运行命令行,我发现它埋在javac的文件访问活动中-考虑到命令行选项,这相当广泛,给您的印象是您在限制文件的查找位置-我发现了

The running the command line in another terminal instance I found buried in the file accessing activity for javac - which is pretty extensive considering the command line options give you the impression that you are restricting where it looks for files - I found

open:entry javac/Users/me/Library/Java/Extensions/tools.jar

open:entry javac /Users/me/Library/Java/Extensions/tools.jar

我没有意识到我有一个本地扩展文件夹.....

I didn't realise I had a local extensions folder.....

删除其中的内容即可解决此问题.

Deleting the contents of it fixed the problem.

所以,这是由旧罐子引起的版本不匹配-正如其他人所发现的-在我的情况下,问题是找到它们

So, it is a version mismatch caused by old jars - as others have discovered - the problem in my case was finding them

这篇关于Java编译错误:Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆