1

When I run my web application with Tomcat, I get an error as follow:

Caused by: Unable to find a javac compiler;

com.sun.tools.javac.Main is not on the classpath.

Perhaps JAVA_HOME does not point to the JDK.

It is currently set to "D:\jdk1.7.0_60\jre"

I set JAVA_HOME in Configuration, but unfortunately no effect.

enter image description here


SDKs setting in Project Structure:

enter image description here

========================================================

Problem has been solved! Application get exception when doing Ant javac task, set the "fork" property true then it find extJavac.

Appreciate @Michael Hobbs and @Dimitri Hautot.

informatik01
  • 16,038
  • 10
  • 74
  • 104
elevenights
  • 128
  • 1
  • 10

2 Answers2

0

JRE means "Java Runtime Environment". There is no javac compiler in it.

The JRE is actually a subfolder of the JDK (Java Development Kit, where the compiler is).

Make sure your paths are correctly set in IntelliJ settings, and refer to the JDK, not the JRE.

EDIT: looking at the proposed path, all starting with "D:\jdk1.7.0_60\jre", maybe you installed a JRE on your computer, instead of a JDK. This might be the cause of the problem.

Dimitri Hautot
  • 438
  • 5
  • 12
  • I just set "D:\jdk1.7.0_60" in jdk home path, but I don't why Intellij use "D:\jdk1.7.0_60\jre" when running application. – elevenights Mar 17 '15 at 09:33
  • The missing class, `com.sun.tools.javac.Main`, is found in my JDK in a *classes.jar* file, which is definitely not in the JRE subfolder of my JDK. Try deleting and declaring again the JDK in Intellij? – Dimitri Hautot Mar 17 '15 at 09:38
  • I use System.getProperty("java.home"), its print D:\jdk1.7.0_60\jre – elevenights Mar 17 '15 at 10:32
  • Do you find anywhere below "D:\jdk1.7.0_60\" the aforementioned file _classes.jar_? If no, I suspect you Windows-wide JAVA_HOME value is indeed pointing to a JRE, not a full JDK. Try fixing this first – Dimitri Hautot Mar 17 '15 at 10:38
  • but System.getenv("JAVA_HOME") print the right path D:\jdk1.7.0_60 – elevenights Mar 18 '15 at 01:13
  • I really think you shouldn't rely on a globally set JAVA_HOME variable. You have to fix the SDK definition in your project settings. As previously asked, do you have the _classes.jar_ file somewhere below D:\jdk1.7.0_60\ ? Or can you install a fresh JDK and use it instead? – Dimitri Hautot Mar 18 '15 at 09:17
0

Project Structure -> SDK does not effect JAVA_HOME. This must be set in the OS. I'm surprised IntelliJ, ran with a JAVA_HOME issues. Should be something alone the lines of:

Linux shell export JAVA_HOME=/home/michael/jdk1.7.0_65

Windows How to set java_home on Windows 7?

Community
  • 1
  • 1
Michael Hobbs
  • 1,663
  • 1
  • 15
  • 26
  • I use System.getProperty("java.home"), its print D:\jdk1.7.0_60\jre – elevenights Mar 17 '15 at 10:32
  • I'm not entirely sure about windows but on Linux that was a no go for me. IntelliJ failed to start with that as the setting. does not work: export JAVA_HOME=/home/michael/jdk1.7.0_65/jre works: export JAVA_HOME=/home/michael/jdk1.7.0_65 – Michael Hobbs Mar 17 '15 at 10:43