IntelliJ IDEA can't run application with JDK - java

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.
SDKs setting in Project Structure:
========================================================
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.

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.

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?

Related

'java' is not recognized as an internal or external command, operable program or batch file

I am using java 12.0.2, JAVA_HOME is set as C:\Program Files\Java\jdk-12.0.2 and PATH is having %JAVA_HOME%\bin
still when I try executing java command its giving me the error 'java' is not recognized as an internal or external command, operable program or batch file.
java and javac are part of JRE and JDK 12 doesn't have JRE now, so how to setup this.
please don't relate this issue with old questions, until java8 it's fine but its not working now in windows 10.
java and javac are part of JRE and JDK 12 doesn't have JRE now, so how
to setup this.
After JDK 10, there is no separate JRE shipped and you do not need a separate JRE anymore. The JDK is enough.
I am using java 12.0.2, JAVA_HOME is set as C:\Program
Files\Java\jdk-12.0.2 and PATH is having %JAVA_HOME%\bin
The space in the path may cause problems. I suggest you set C:\Program Files\Java\jdk-12.0.2\bin directly into PATH. Also, make sure to promote this entry to the top (beginning) so that this entry overrides the existing Java version (if any).
Last but not the least, start a new cmd window session to check java -version because the changes in the environment variables using the GUI does not become effective in already open cmd windows.
For any misconfiguration, if you can not make it work, download a fresh JDK and follow the instructions on the download page.
Try removing any existing java paths and making sure your JAVA_HOME is correct. There is no JRE but the java command should work if your env vars are correct. It is most likely a configuration error so deleting old configuration and reconfiguring will probably hlep.
The problem was caused by Python which was not allowing to execute java/javac commands. Once I uninstall the python everything worked fine.
I am still not sure what happened when I install Python as I explicitly didn't do anything except enabling the tick mark to setup the path variable while installing it.

eclipse open error failed to find main class in eclipse\\plugins/org...jar

at the beginning it says that failed to find java jdk or jre so i installed it. then i run it again it came up this.
It says that "Failed to find a Main Class in ... eclipse\\plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar"
java file are under
C:\Program Files (x86)\Java\jre1.8.0_31 && jre7
C:\Program Files\Java\jdk1.8.0_31 && jre1.8.0_31
my eclipse file are under
D:\迅雷下载\操作系统\eclipse
can someone tell me how to fix this ??
I was facing the similar issue where on launching eclipse photon it was giving error like:
Failed to find a Main Class in ...
eclipse\\plugins/org.eclipse.equinox.launcher*.jar
One of the reasons in my case was that I had two JDK versions on my system (JDK 6 & JDK 8).
It was running fine but stopped when I updated JAVA_HOME as JDK 6.
To rectify it, I added the below lines in the eclipse.ini file before -vmargs:
-vm
C:/Program Files/Java/jdk1.8.0_111/bin/javaw.exe
-vmargs
Basically, I passed the JDK 8 path to the eclipse as required version for eclipse photon was Java 8. And this got me working.
Try to move eclipse to some simpler path, like D:\development\eclipse
This error is due to because you might have downgraded the version of java in your environmental variables.Try changing the java version in environmental variables and then run the sts or eclipse..for better practice restart the system.hope it helps.!!
I do not mean to steal the first answer - it did help me solve my very similar issue.
I am running Windows 8 x64 bit and installed a modded version of Eclipse in a custom path (rather the default install location that was suggested) - and I got that error.
So, I deleted that Eclipse install. Then installed both x86 and x64 versions of JDK (to their default install locations), and repeated the Eclipse install to the default install location - that solved the problem for me!!!
The reason I installed both JDK versions was because I initially installed only the x64 bit version and a different error came. So I removed that Eclipse again, and repeated the JDK with both versions, etc...
I was on this problem for like an hour and a half not getting that if you save the eclipse file in a non-English named folder it doesn't open.
Hope it helps :)
Check if there are 2 Java paths mentioned in the system Variable "Path"
If yes, Move up the Java path which is mentioned in JAVA_HOME.
For example:
If JAVA_HOME=C:\Program Files\Java\jdk1.8.0_211
then the Path should have same Java version's path
Path=C:\Program Files\Java\jdk1.8.0_211
In my case I just changed the Path from
Path=C:\Program Files\Java\jdk1.6.0_45\bin
To
Path=C:\Program Files\Java\jdk1.8.0_211
Remove Eclipse from Non English folder if any.
This is issue might be because of the folder location or the JDK version,
I installed the latest version JDK and with eclipse-inst-win64 provided by eclipse i was able to install and run successfully
Same thing happens when you change eclipse.exe to a different name, seems like org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar starts the ide and looks for eclipse.exe
In my case, the Eclipse installer downloaded the wrong VM vertion. I download it separately. Choose it in clause "Java 11+ VM" and it works. Also check you do not have Russian letters in eclipse.ini. If you do, then change the encoding to UTF-8 and write the right letters in Russian.

Building older NetBeans project in bash leads to error

I am opening an older NetBeans project and I want to build it using ant in bash with debian. However, when I try to run ant, I get this error
BUILD FAILED
/home/karelbilek/NetBeansProjects/oldProject/nbproject/build-impl.xml:528:
The following error occurred while executing this line:
/home/karelbilek/NetBeansProjects/oldProject/nbproject/build-impl.xml:261:
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 "/usr/lib/jvm/java-7-openjdk-i386/jre"
What does that mean? What should I do? In "/usr/lib/jvm/java-7-openjdk-i386/jre" there seems to be an actual JRE when I look there, so what is the problem?
You're pointing to a JRE (Java runtime environment) but not a JDK (Java development kit).
Only the JDK contains the compiler (javac). The JRE is used for running Java programs but doesn't carry the extra components of the JDK (compiler etc.)
it happened for me and i got through it by installing the jdk
sudo apt-get install openjdk-7-jdk
After installing jdk, the classpath executed right

JAVA_HOME does not point to the JDK

I am trying to follow a tutorial about how to use ant to build and run your application. I've followed all the steps and have created the build file, but when I try to run ant it gives me this error.
BUILD FAILED
/home/bilal/tmp/ant/build.xml:19: 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 "/usr/lib/jvm/java-6-openjdk/jre"
Any ideas how to resolve this issue ?
Make JAVA_HOME variable point to a jdk installation, not jre.
You are referencing the runtime environment, not the development kit - it can't find the compiler because its not there.
From the line you posted, which states you have open-jdk you can just remove the jre at end:
export JAVA_HOME='/usr/lib/jvm/java-6-openjdk/'
You installed java...
apt-get install default-jre
But not the JDK...
apt-get install default-jdk
This is by design. You cannot use ant's java.home (which is a java.lang.System property) interchangeably with how JAVA_HOME is set in the OS environment. You are probably trying to assert the location of the Java compiler with a fundamentally different value from a different property layer -- i.e. java.home (from Ant's Java internals) points to the Java Runtime Environment at <any_installed_java_pointed_to_by_ant>/jre while JDK_HOME (from the OS environment) is usually set to <DOWNLOADED_AND_INSTALLED_JAVA_DEVELOPMENT_KIT>.
See my question and answer here for more details: Where does Ant set its 'java.home' (and is it wrong) and is it supposed to append '/jre'?
The solution is to access the system environment property within Ant by using ${env.JAVA_HOME}. Specify which java to use explicitly in the Javac Task by setting the executable property to the javac path and the fork property to yes (see Ant's Javac Task Documentation). That way, it doesn't matter what Java environment Ant is running inside, the compiler is always clearly specified!
I know this question is old but the accepted answer does not work anymore and since this is the fist link on google search i'll tell how i solved this problem.
for eclipse using ubuntu:
go to Window->Preferences->Ant->Runtime->Select Ant_Home_Entries and click on add external jars then find in file explorer where your jdk is (default is in /usr/lib/jvm/) and in the lib folder of your jdk you will find the tool.jar. select this one and click apply.
try to build your project and things should work!
note: i hadn't used ant for a long time but needed it for ycsb couchbase workload generator (http://www.couchbase.com/wiki/display/couchbase/Load+Generator+Setup) if anyone is/was stuck on this.
It looks like you are currently pointing JAVA_HOME to /usr/lib/jvm/java-6-openjdk/jre which appears to be a JRE not a JDK. Try setting JAVA_HOME to /usr/lib/jvm/java-6-openjdk.
The JRE does not contain the Java compiler, only the JDK (Java Developer Kit) contains it.
I am using Windows 7 and have struggled with the same issue. I fixed it by changing my environment variables.
To change your environment variables click here
I added ";%JAVA_HOME%/bin" to the end of paths variable and added a new "JAVA_HOME" variable and set its value to the location of my JDK "C:\Program Files\Java\jdk1.8.0_11". After that I restarted my Node.js command prompt and it worked.
Please note you JDK directory may be different then mine. Also depending on your setup, you may need to restart you computer after setting the environment variables.
The JAVA_HOME you have above only points to the JRE, which does not contain the compiler. Set your JAVA_HOME to
/usr/lib/jvm/java-6-openjdk
...and try again.
I had a similar problem and it turned out the issue was having both versions 6 & 7 of OpenJDK. The answer comes from r-senior on ubuntu forums (http://ubuntuforums.org/showthread.php?t=1977619) --- just uninstall version 6:
sudo apt-get remove openjdk-6-*
make sure that JAVA_HOME and CLASSPATH aren't set to anything since that isn't actually the problem.
for centos yum -y install java-1.7.0-openjdk-devel.x86_64
and update JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86-64
I just copied tools.jar file from JDK\lib folder to JRE\lib folder. Since then it worked like a champ.
Experienced this issue when trying to run the android emulator with Meteor 1.0 on elementary OS Luna (based on Ubuntu 12.04 LTS sources).
openjdk-6-jdk was installed, as well as the jre. In the end, not expecting any success, I tried:
sudo apt-get remove openjdk-6-*
this resulted in fully expected errors, so I followed up with
sudo apt-get install openjdk-6-jdk
and things worked. Go figure.
On Ubuntu 14.04, I found two parts to solving the problem:
Remove /jre from the environment variable. For me: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
Install the JDK as well as the JRE: sudo apt-get install default-jdk
Once you update the JAVA_HOME path as stated in the answer, you should do this:
$source ~/.bashrc
This will refresh bashrc show the updated path in $JAVA_HOME when you check again.
Execute:
$ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-3.b16.el6_9.x86_64
and set operating system environment:
vi /etc/environment
Then follow these steps:
Press i
Paste
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-3.b16.el6_9.x86_64
Press esc
Press :wq
I met this issue in rhel, my "JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk"(which is a symbolic link), and ant complains.
MY solution for this is to use the real jdk path in JAVA_HOME, like:
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64
It works for me.
Under Jenkins it complains like :
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/ doesn’t look like a JDK directory
Reason : Unable to found any Dev Kit for JDK.
Solution:
Please make sure to install openjdk-devel package as well along with your JDK-1.8* version and reexport with : # source ~/.bash_profile

Ant and Eclipse

Hi I am a beginner java programmer and recently I've started reading Thinking in Java 4th edition to consolidate my knoledge of java after I read Head first Java.Problem is that this book has it's own library and I can't seem to make it work in eclipse even after I did everything it said on the website guide.I instaled ant acordinly with this video guide http://www.youtube.com/watch?v=XJmndRfb1TU and i'm getting this error:
"Unable to locate tools.jar.Expected to find it in C:\Program files\Java\jre7\lib\tools.jar
Buildfile:C:\TIJ4\code\build.xml
build:
BUILD FAILED
C:\TIJ4\code\build.xml:59:J2SE5 required
Total time:0 seconds
I tried reinstaling JDK witch was suggested on a forum but it still dident work so I don't really know what to do.
Can anyone tell me how can I solve this problem? Also, more importantly, can't this be done with Eclipse alone without installing Ant(I've only used eclipse for code writing and compiling so I'm not very familiar with it)Thant you.
You are using a JRE instead of a JDK. Install a JDK and point your PATH and JAVA_HOME variables to the JDK home, not to the JRE home.
I see that Ant is using the Java Home from the JRE, e.g. C:\Program files\Java\jre7\
But it should be C:\Program files\Java\jdk1.7.0\ or similar.
Check your system's environment variables (e.g. press Windows-Key and Pause together, then select Extended Settings > Environment Variables. Check that JAVA_HOME is set to the JDK installation path and that in the PATH variables, the folder of the JDK comes before the folder of the JRE (or remove/replace the JRE path altogether with the one from the JDK).
Ant needs to find the JDK first in the PATH.
Install the JDK, latest version, and check the environment variable JAVA_HOME.
If it is not found, create it and set it to C:\Program Files\Java\jdk1.7.0 ...
tools.jar contains the java compiler, and only comes with the Java Development Kit (JDK). Your error message point to the Java Runtime (JRE).
From Eclipse, you set that from Window/Preferences/Java/Installed JREs. This is equivalent to, and will override, the alternative way of setting it via Windows environment variables.
I tried installing the JDK - jdk1.7.0_09
and did whatever was needful in the Environment Variables section
but i still was getting this error
"Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed"
Tools.jar file did not really exists in this path, instead i found it in C:\Program Files\Java\jdk1.7.0_09\lib
so i simply copied this tools.jar file and placed it under C:\Program Files\Java\jre7\li
b\
and it worked - (not sure if that was the right way)
Now when i typed in the cmd prompt "ant" it gave me the below error :
Buildfile: build.xml does not exist!
Build failed
On investigating it further i found that if you get the above error it means that ant is installed successfully
http://ant.apache.org/manual/install.html#getBinary - Check Installation
what ivantrox86 said is true, but you need to do it in all the build.xml files, and there are like 20 of them. so go to each and every folder in the c:\tij4\code directory and find every build.xml file, and change the second argument (arg2) to 1.5, instead of the default value (${ant.java.version}). works 100%
This can happen with ant if JAVA_HOME is set incorrectly - it seems to try to guess what the value should be and comes up with the jre7 address. In my case setting JAVA_HOME to C:\Progra~1\Java\jdk1.7.0_45 fixed the problem. Of course the address will vary depending on where your jdk is installed.
please search and change this line in all files.:
<equals arg1="1.5" arg2="${ant.java.version}"/>
for
<equals arg1="1.5" arg2="1.5"/>

Categories