Estoy tratando de ejecutar la aplicación Java y recibo el siguiente error,
No se puede encontrar un compilador javac; com.sun.tools.javac.Main no está en el classpath. Quizás JAVA_HOME no apunta al JDK
He pasado por muchas preguntas SO y la solución encontrada es JAVA_HOME debe apuntar a JDK, no a JRE .
Luego intenté imprimir JAVA_HOME en el símbolo del sistema,
Había configurado este JAVA_HOME desde mi computadora-> propiedades-> variables env -> sistema vars como se muestra a continuación,
También había agregado una nueva variable en eclipse usando preferencias como,
Y finalmente sigo recibiendo el mismo error. ¿Qué pasa con JAVA_HOME?
Actualización:
In eclipse-preferences-installed jres
there is only one entry is present and which is jdk and selected,
And under project properties
java build path
-libraries
there is JRE System Liberary [jdk1.8.0_31]
is used.
Update 1 :
C:\Program Files\Java\jdk1.8.0_31
have folder named jre
. Is that jre
folder causing this issue ? Can I remove this folder ? Is there is any way to add only jdk liberary in project ?
Eclipse is an IDE and as such, it has (at least) two Java versions: The one which it uses itself to run (JAVA_HOME
) and a JVM which it uses to run your application. The two don't need to be the same.
So to fix your problem, you need to look into Eclipse's preferences, specifically Installed JREs
which gives you a list of Java VMs which Eclipse will use to run Java code from projects. My guess is that there will be several entries there and the default will be a JRE instead of a JDK.
Make sure you have a JDK in the list and then go to your project. In the project, you can select which Java VM to use under Java Build Path
-> Libraries
.
[EDIT] Look closely at the last screenshot: You've configured Eclipse to use C:\Program Files\Java\jdk1.8.0_31\jre
which means you've pointed it at the JRE inside of the JDK. Use C:\Program Files\Java\jdk1.8.0_31
instead (without the \jre
at the end).
[EDITAR 2] Si elimina la jre
carpeta, Java dejará de funcionar. Cualquier JDK también contiene un JRE. El JRE contiene rt.jar
con String.class
y similares. El compilador de Java está en el tools.jar
que está en el JDK.
Si recrear la entrada JRE en Eclipse no ayuda, tendrá que agregarlo manualmente a la ruta de clase.
Puede usar una variable ("Agregar variable ...") para asegurarse de que Eclipse actualice la ruta cuando cambie a un JRE nuevo / diferente. Prueba JAVA_HOME
con la extensiónlib/tools.jar
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras