10

I have downloaded both Java jdk1.7.0_06 and Java jre7. and i added the following system variable JAVA_HOME C:\Program Files\Java\jdk1.7.0_06\bin to my windows 7. But when I type the following in the CMD command line on my windows 7 C:\activiti-5.10\activiti-5.10\setup>ant demo.start to run a demo application I got the following error in the command line '

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

So does anyone know how i can solve this problem ? BR

imulsion
  • 8,820
  • 20
  • 54
  • 84
John John
  • 1
  • 72
  • 238
  • 501
  • Duplicate or cause of error. You did some thing more in the setup? http://stackoverflow.com/questions/12073535/unable-to-run-the-demo-setup – Jayan Aug 26 '12 at 12:32

8 Answers8

17

If you look at the "ant.bat" file, you will see that it looks for the "java" command in the following way:

  1. If the %JAVACMD% environment variable is set, then it uses that.
  2. Otherwise, if the %JAVA_HOME% environment variable is set, it tries to use %JAVA_HOME%\bin\java.exe
  3. Otherwise, it tries to use java.exe; i.e. it will look on your %PATH%.

In your case, you have %JAVA_HOME% set ... but set to the Java installation's "bin" directory, not to the root of the installation. So the Ant.bat script looks in the wrong place for java.exe.

Just set %JAVA_HOME% correctly, and it should work.

JAVA_HOME C:\Program Files\Java\jdk1.7.0_06

As you can see from the above, you do not need to have the Java "bin" directory on your %PATH% for Ant to work, but it is a good idea to set it anyway. That way you can run the Java commands simply from the command line.

The setting of %CLASSPATH% is not relevant to this problem. Indeed, unless the build.xml file is broken, Ant will ignore your %CLASSPATH% environment variable.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • ok thanks for the reply, i changed the JAVA_HOME to be C:\Program Files\Java\jdk1.7.0_06. and now the tomacat server will start successfully when i type "C:\activiti-5.10\activiti-5.10\setup>ant demo.start". But when i navigate to the following link http://localhost:8080/activiti-explorer ,, then i will get the following error "The requested resource (/activiti-explorer) is not available". any idea how can i solve this problem? – John John Aug 26 '12 at 07:40
  • That is not an Ant problem. That is a problem with the product you are trying to use and/or the instructions you are following. Ask as a new question ... and ask on Superuser rather than SO. – Stephen C Aug 26 '12 at 07:43
  • thanks for the reply,, i just added C:\Program Files\Java\jdk1.7.0_06\bin to my PATH and it worked fine. – John John Aug 26 '12 at 14:00
  • @StephenC I have the same problem and tried what you have said before, but still I got stupid response in jenkins : 'C:\Windows\system32\java.exe' is not recognized as an internal or external command What could be the problem and what is the solution for that? – meakgoz Jan 24 '14 at 15:28
  • @MeM - What have you set `%JAVA_HOME%` to? The problem is most likely that you've set it incorrectly. – Stephen C Jan 25 '14 at 00:10
  • @StephenC thank you for your concern. I have found the solution (delete the file as explained in this link: https://coderwall.com/p/gbek2g ). Maybe it helps also someone. – meakgoz Feb 14 '14 at 15:21
  • 1
    @MeM - Yes, that can work. But it could also break other things; e.g. if some other application depended on the Java tools that you just deleted. – Stephen C May 29 '16 at 03:09
1

You need to put the file java.exe in your PATH variable but the JRE in JAVA_HOME

imulsion
  • 8,820
  • 20
  • 54
  • 84
  • thanks for the reply , actually the java.exe are in the bin folder for both the java jdk1.7.0_06 and Java jre7... – John John Aug 26 '12 at 07:05
  • @imulsion - If you have `%JAVA_HOME%` set *at all*, `%PATH%` won't be used by the `ant.bat` script. – Stephen C Aug 26 '12 at 07:46
1

Typically JAVA_HOME should be the parent directory of the "bin" folder.(jre or jdk)

In this case ant expects the java to be from the JDK.

try following in a cmd window

set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_06
set path="%JAVA_HOME%/bin;%path%;
ant

(side note: adding java.exe to path is not a requirement for ant; it is a convenience thing for the user)

Jayan
  • 18,003
  • 15
  • 89
  • 143
  • thanks for the reply ,, i tried the above commands and they will start the tomcat server successfully,, but when i typed >>ant demo.start i will get the same original Java.exe error?? ant thing i can do ? – John John Aug 26 '12 at 07:03
1

JAVA_HOME is the path of JDK root folder.eg: C:\Program Files\Java\jdk1.7.0_06 but path define C:\Program Files\Java\jdk1.7.0_06\bin

JAVA_HOME C:\Program Files\Java\jdk1.7.0_06
JRE_HOME C:\Program Files\Java\jre1.7.0_06
path = C:\Program Files\Java\jdk1.7.0_06\bin;C:\Program Files\Java\jre1.7.0_06\bin
Mohammod Hossain
  • 4,134
  • 2
  • 26
  • 37
  • thanks for the reply first of all i think you mean jre7 instead of jre1.7.0_06. now when i type ">>ant demo.start" it will give me that the Build Successful. But the java.exe cmd window will open then disappear so the server will not start... any idea what is causing this ,, java.exe cmd window should open automatically and keep running ... – John John Aug 26 '12 at 07:21
1

Just delete the following set of files from your %windir/System32 folder. Actually deleting java.exe is enough but for consistency sake just delete all the java related binaries.

  1. java.exe
  2. javaw.exe
  3. javaws.exe

Actually oracle windows installer places a copy of these files into %windir/System32 folder (which I don't understand why) but looks like they are not needed (as they are available anyway under JDK folder where you install them).

I have tried all the various solutions posted in the SO and other forums as well but none of them worked for me. I have also set all the relevant environment variables (JAVA_PATH, CLASS_PATH etc) correctly as well. Finally this is the only solution that has worked for me.

0

Go to the \squirrel-sql-3.9.0>squirrel-sql.bat .open that squirrel-sql.bat in Notepad and comment out the existing logic which is

=======================================
if exist "%IZPACK_JAVA%\bin\javaw.exe" (
  set LOCAL_JAVA=%IZPACK_JAVA%\bin\javaw.exe
) else (
  set LOCAL_JAVA=javaw.exe
)

echo Using java: %LOCAL_JAVA%
=================================

and add the below logic

@echo off

set LOCAL_JAVA=C:\Program Files (x86)\Java\jre7\bin\javaw.exe

echo Using java: %LOCAL_JAVA%
================================

make sure you add the correct path of javax.exe while adding above logic set LOCAL_JAVA=

and start the .bat file from CMD ..that's it. It should work. It worked for me.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

I started getting this error in Android Studio after I updated it to version "Electric Eel".

It happened because Android Studio has changed where they put their JRE:

  • it used to be C:\Program Files\Android\Android Studio\jre
  • but now it is C:\Program Files\Android\Android Studio\jbr

To fix:

  1. updated my JAVA_HOME environment variable to point to the new java location (C:\Program Files\Android\Android Studio\jre)
  2. and then restarted Android Studio, and now it is fixed.
Eric
  • 16,397
  • 8
  • 68
  • 76
-1

I agree with the above explanation but if the problem still persists try setting: CLASSPATH = C:\Program Files\Java\jdk1.7.0_06\bin

imulsion
  • 8,820
  • 20
  • 54
  • 84
  • thanks for the reply,, i added the above environment variable,, but now when i type ">>ant demo.start" it will give me that the Build Successful. But the java.exe cmd window will open then disappear so the server will not start... any idea what is causing this ,, java.exe cmd window should open automatically and keep running ... – John John Aug 26 '12 at 07:26
  • The classpath is not relevant to the problem. If it was relevant, the error message would be different. – Stephen C Aug 26 '12 at 07:45
  • 1
    the classpath has absolutely **nothing** to do with finding the .exe. And besides it shouldn't be used anyway. Defining a global classpath usually creates more problems than it solves. –  Aug 26 '12 at 07:48
  • I would suggest to check 2 things in your environment: 1. Remove any java path from environment variables(My computer --> ... Environment variables). 2. Try running a sample program by setting path for jdk/ jre. – Shera A Khan Aug 26 '12 at 08:29