简体   繁体   English

无法使用Java 1.8

[英]Unable to use Java 1.8

I'm having trouble using eclipse/intelliJ because whenever I try to check java version, this is what I will get. 我在使用eclipse / intelliJ时遇到了麻烦,因为无论何时我尝试检查java版本,我都会得到它。 But java is present in the system preferences pane. 但java存在于系统首选项窗格中。

$ java -version
Unable to locate an executable at "/usr/libexec/java_home/bin/java" (-1)

If you're on Mac, do this: 如果您使用的是Mac,请执行以下操作:

export JAVA_HOME=$(/usr/libexec/java_home)

or: 要么:

export JAVA_HOME=`/usr/libexec/java_home`

Instead of this: 而不是这个:

export JAVA_HOME=/usr/libexec/java_home

or: 要么:

export JAVA_HOME="/usr/libexec/java_home"

Looks like java is installed but classpath is not set. 看起来像是安装了java但没有设置classpath。 please try following command in terminal to set the java path. 请在终端中尝试以下命令来设置java路径。

export JAVA_HOME=/usr/libexec/java_home/bin/java
export PATH=$JAVA_HOME/bin:$PATH

Once this is done then check the java version. 完成后,检查java版本。 Hope it helps. 希望能帮助到你。

Check that java 8 is in your PATH or whatever it is called on windows if you are using windows. 如果您使用的是Windows,请检查java 8是否在您的PATH中或在Windows上调用它。

If that's not the problem, consider uninstall and install again java, something might have gone wrong back when you installed it. 如果这不是问题,请考虑卸载并再次安装java,安装时可能会出现问题。

It none of this works, could you show us your intelliJ or eclipse settings about Java location ? 这一切都没有,你能告诉我们你关于Java位置的intelliJ或eclipse设置吗?

I can now run my java programme in IntelliJ Idea. 我现在可以在IntelliJ Idea中运行我的java程序。

May be one day I will do the same by helping somebody out. 也许有一天我会通过帮助别人来做同样的事情。

Solution was: 解决方案是:

First I would like to give a context. 首先,我想提供一个背景信息。 I had deleted 'Java' folder under 我删除了'Java'文件夹

/HDD/library/ / HDD /库/

On my mac, because I was trying to uninstall all legacy versions of Java. 在我的Mac上,因为我试图卸载所有旧版Java。 Then on Oracle site, I read that I should have kept default (java 1.6) to facilitate Eclipse installation. 然后在Oracle站点上,我读到我应该保持默认(java 1.6)以便于Eclipse安装。

Then: 然后:

  1. downloaded java 1.6 on apple website - https://support.apple.com/kb/DL1572?locale=en_US 在苹果网站上下载了java 1.6 - https://support.apple.com/kb/DL1572?locale=en_US

  2. used @vaibhav Jain's solution to set/point to my jdk folder instead of default one. 使用@vaibhav Jain的解决方案设置/指向我的jdk文件夹而不是默认文件夹。 By using this: 通过使用这个:

     export JAVA_HOME=/usr/libexec/java_home/bin/java export PATH=$JAVA_HOME/bin:$PATH 
  3. Dowloaded jdk 1.8 from Oracle website to update my java - http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 从Oracle网站下载jdk 1.8以更新我的java - http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

  4. Tried checking the java version on terminal by $ java -version 尝试通过$ java -version检查终端上的java版本

  5. Confirmed that it was showing the updated version. 确认它显示的是更新版本。

  6. Tried running java programs, and I was able to without any error messages! 尝试运行java程序,我能够没有任何错误消息!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM