So I am new to using and creating batch files. I was wondering what is wrong with my file. I want to make it where it sets the path so I can compile my java file in cmd. Here is my code
#echo off
:start
rem set path="c:\Program Files\java\jdk.1.8.0_102";
set path=%path%;c:\Program Files\java\jdk.1.8.0_102
cls
pause
rem goto start
I am not to sure which one is right between the 2 paths so I was just testing.
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";
JAVA_HOME: stores location of the JDK’s installation directory.
PATH: stores paths of directories where the operating system will look, to launch the requested programs quickly.
Try this:
set path="C:\Program Files\Java\jdk.1.8.0_102\bin";%path%
Related
Im trying to run a simple RMI application via batch file.
I have been given these lines by my instructor to write in notepad and save it as .bat :
#cd %cd%\src
#for /r %%a in (*.java) do #javac %%a
#start rmiregistry 3000
#java Server
#pause
When I run the batch files it shows that 'javac is not recognized as an internal or external command operable program or batch file', and for the RMI it shows 'The system cannot find the file rmiregistry'.
I searched for solutions for 'javac' problem and it appears I have to set a path for it in the 'Environment Variables' which I did via adding a new USER variable in the name of JAVA_HOME and the path : 'C:\Program Files\Java\jdk1.8.0_40\bin'
The problem is consistent and I don't know where to start to solve it
You should append this $JAVA_HOME environment variable in the PATH environment variable. This will solve your problem.
OR Alternatively,
you should directly add this directory location to the end of the PATH environment variable.
PATH=........;C:\Program Files\Java\jdk1.8.0_40\bin
// here ....... denotes previous entry done already in PATH
Or, SET Path by typing the following in the CMD(console/command prompt) as :-
set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_40\bin
I am trying to launch a .bat file but I get the error
System cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe
I understand that this is probably a path variable, but I have not been able to understand how to fix it, if that is the problem.
Thanks in advance.
First of all, the path that you provided i.e. C:\ProgramData\Oracle\Java\javapath\java.exe doesn't appear to be correct. It should point to either JRE or JDK folder that you (probably) have in here:
C:\Program Files (x86)\Java\jdk1.8.0_25\bin
In there you should at least see the following files (and hence, the addition of this bin directory to your PATH variable in the env vars):
java.exe
javac.exe
javaw.exe
javap.exe
java.h.exe
java-rmi.exe
javadoc.exe
jarsigner.exe
jar.exe
If you don't see the files above, something is definitely wrong! Also, even if you were using JRE (not JDK), you should still have this bin folder present, where java.exe resides.
I had the same problem. Here's what worked for me:
Go into your path variable and delete: C:\ProgramData\Oracle\Java\javapath\.
Then add a new one called: %JAVA_HOME\bin
This post helped: java-path-is-not-pointing-to-sdk-path-in-windows
Edit: Sorry, I just noticed that this question was 3 years old.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#ECHO OFF
:: Export java settings from registry to a temporary file
START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft"
if not exist "%Temp%\java.reg" (
START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft"
)
if not exist "%Temp%\java.reg" (
echo java not installed
exit /b 1
)
:: Find java location
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%\java.reg ^| FIND "INSTALLDIR"') DO SET "JAVA_HOME=%%B"
SET "JAVA_HOME=%JAVA_HOME:"=%"
SET "JAVA_HOME=%JAVA_HOME:\\=\%"
::SET JAVA_HOME
set "java=%java_home%\bin\java.exe"
"%java%" -version
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Try this to see if you can automatically can detect the java location.And if it's work you can put this at the beginning of your script and use %java% in your script (though it will decrease the performance).
I am setting Environment Variable, Still OS cant recognise. Check this out you will get it.
https://www.dropbox.com/s/raqr4wbtoxxz0b8/1.JPG
I tried with Admin privileges also still same but when I enter
echo %java_home%
or
echo %jre_home%
It is showing path corretly. Why isnt javac command working.
Any Help will be appreciated.
You don't have javac in your path. Setting the JAVA_HOME and/or JRE_HOME environment variables (which aren't needed any more, for the most part) does nothing to the PATH which the command shell uses to find executables.
Put the relevant JDK bin directory in your PATH environment variable instead - and unless you actually need JRE_HOME and JAVA_HOME for some reason, I'd get rid of them. If you do need them, get rid of the "bin" part - it should just be the root JRE directory, e.g.
c:\Program Files\Java\jdk1.7.0_45
Your path JAVA_HOME should be, for example
C:\Program Files\Java\jdk.1.7.0_45
And your Path variable should be
...;%JAVA_HOME%\bin
javac is in the bin folder which should be on your path.
That has nothing to do with Java environment variables.
When you type javac, or any other command, Windows will search the folders in the %PATH% environment variable to find an EXE file with that name.
You need to add your JDK directory to %PATH%.
You also need to restart cmd to pick up the changes.
Include the JRE/JDK path in System variables->PATH as well
After adding path varaibles,restart the cmd
You must restart cmd for new variables to be picked up. And java bin folder needs to be included in path. When you type javac it goes through all folders defined in path to find it.
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
If you look at the "ant.bat" file, you will see that it looks for the "java" command in the following way:
If the %JAVACMD% environment variable is set, then it uses that.
Otherwise, if the %JAVA_HOME% environment variable is set, it tries to use %JAVA_HOME%\bin\java.exe
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.
You need to put the file java.exe in your PATH variable but the JRE in JAVA_HOME
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
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)
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.
java.exe
javaw.exe
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.
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.
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:
updated my JAVA_HOME environment variable to point to the new java location (C:\Program Files\Android\Android Studio\jre)
and then restarted Android Studio, and now it is fixed.
I agree with the above explanation but if the problem still persists try setting:
CLASSPATH = C:\Program Files\Java\jdk1.7.0_06\bin
I have a stanalone application with a main class which used to run a windows BAT file ,the BAT file which invoke another java class(B),the class B refer so many JARs and configuration files which i configured through "build Path"
Now I want to refer the JARs and configuration files in BAT file.How I write the BAT file.
If you can make sure the .bat file and all needed jars are located in the same directory, this is quite easy:
rem sets the basedir to the directory where this batch file is locaed
set basedir=%~dp0
rem build the classpath for the Java command
set cp=%basedir%\jar_one.jar
set cp=%cp%;%basedir%\jar_two.jar
set cp=%cp%;%basedir%\jar_three.jar
(and so on...)
rem start your second class
java -cp %cp% your.package.ClassB
Is the program specific to one machine or does it need to be generic?
The issue would be, I think, would be how to get a jar file to return something outside of java. The obvious answer would be, use the batch file to run the java. Write the java so that it writes its 'return value' to a file. Write the batch file so that it watches for the file/dir that the java writes to, and looks for the changed/new data and then use it.
REM if all jar files contains in ./lib dir:
setlocal enabledelayedexpansion
for /r "./lib" %%a in (*.jar) do (set "CP=%%a;!CP!")
REM start your second class
java -cp %CP% your.package.ClassB