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
Related
I have a Java jar file located in:
C:\Users\myusername\bin\MyDir\MyApp.jar
I also have some required properties files (needed as input arguments to the .jar file) located in the same directory as the .jar file.
I created a runme.bat file here:
C:\Users\myusername\Desktop\runme.bat
In the runme.bat file, this is what I have:
setlocal
set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_161\bin\"
set PATH=C:\Users\myusername\bin\MyDir\
start %JAVA_HOME%javaw -jar %PATH%MyApp.jar %PATH%propertiesfile.properties
However, whenever I try to run the .bat file, I get the error:
Windows cannot find '-jar' Make sure you typed the name correctly, and then try again.
On the command line I see Windows trying to do this:
> "C:\Program Files\Java\jdk1.8.0_161\bin\"javaw -jar C:\Users\myusername\bin\MyDir\MyApp.jar ...
I get this error when running from the command line. If I simply double-click the .bat file, a cmd window comes up and quickly disappears.
So, what am I doing wrong?
Thanks!
Use Double quotes around the set command, not inside the variables.
Also, I see no reason to use the START command unless you want to do more in your batch file in the original command prompt after starting your Java in a second command prompt. Possible but seems unlikely.
Generally, you will just type in the executable or use CALL so that the executable runs and control returns to the batch after reaching conclusion.
Additionally, you changed your system path variable to be just the path of your java files which will make the session pretty screwy. Thankfully this should only persist in your open command windows and those spawned by the original window, so close them all and then use a different variable name for your path.
So I will put this both ways, using Call, and using start.
Here is your code using call:
#(
setlocal
ECHO ON
)
set "_Title=Runnning My Java"
set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161\bin"
set "_MyJarPath=C:\Users\%UserName%\bin\MyDir"
TITLE "%_Title%"
CD /D "%JAVA_HOME%"
CALL "%JAVA_HOME%\javaw.exe" -jar "%_MyJarPath%\MyApp.jar" "%_MyJarPath%\propertiesfile.properties"
(
ENDLOCAL
EXIT /B 0
)
Here is your code using the start command:
#(
SETLOCAL
ECHO ON
)
set "_Title=Runnning My Java"
set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161\bin"
set "_MyJarPath=C:\Users\%UserName%\bin\MyDir"
start "%_Title%" /D "%JAVA_HOME%" "%JAVA_HOME%\javaw.exe" -jar "%_MyJarPath%\MyApp.jar" "%_MyJarPath%propertiesfile.properties"
(
ENDLOCAL
EXIT /B 0
)
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%
I'm trying to use Jmeter but am coming across an issue when I try and run it using the Jmeter.bat file.
It's spits out the following error:
'java -version 2>&1 | findstr /i "version"' is not recognized as an internal or external command, operable program or batch file.
Not able to find Java executable or version. Please check your Java installation.
errorlevel=2
Press any key to continue . . .
I've tried googling this and lots of posts mention that this error is usually down to the environment variables not being set correctly, but I'm fairly sure they are as if I type java or javac into the command prompt I get a response.
I've got them set as follows:
JAVA_HOME : C:\Program Files\Java\jdk1.8.0_25
JDK_HOME : %JAVA_HOME%
JRE_HOME : %JAVA_HOME%\jre
CLASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
PATH : your-unique-entries;%JAVA_HOME%\bin
I tried taking the string it's complaining about and pasted that into the command prompt by itself and it ran fine:
C:\Windows\System32>java -version 2>&1 | findstr /i "version"
java version "1.8.0_25"
So why is it throwing the error when running the batch file but not if I paste it in manually? The batch file is located in a folder in my C drive and I'm running by right clicking and selecting 'Run as Administrator'. If I just double click the .bat file I get the error:
Windows cannot find 'C:\apache-jmeter-2.13_src\bin\jmeter.bat'. Make sure you typed the name correctly, and then try again
Is the above error related or is that a separate permissions issue?
Thanks for any help
From command Prompt go to bin folder of apache jmeter and type following command:
C:\apache-jmeter-3.0\bin> java -jar ApacheJmeter.jar
I also faced similar problem when I extracted the JMeter in C. In my case, i don't have admin rights. I assume it is related to some permission issue. So better copy to D: and then check.
Copy C:\apache-jmeter-2.13_src folder to other drive (D:) or download JMeter and extract in D drive and run the batch file.
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 write a bat script to set java path in envirnment variable.
I use following command to set path -
setx PATH=%jdkDirDest%\bin;%PATH%.
setx PATH=%playDirDest%;%PATH%.
set PATH=%jdkDirDest%\bin;%PATH%.
set PATH=%playDirDest%;%PATH%.
It works fine when I am working with current session But what happen if I closed current command prompt and again open and run following command
java -version
javac etc.
It shows no java version is intall in this system
Can any one sugest me what code I use to set these environment path permanently to my matchine using bat command.
** I need bat command.
You have to use setx without the '=', and set with it.
Also use quotes for the values of the environment variables
setx PATH "%jdkDirDest%\bin;%PATH%"
setx PATH "%playDirDest%;%PATH%"
Simply create a autoexec.bat in c:/ drive and write the following line in the file
set path=path to java home folder;
The path should not contain any white space.
save the autoexec.bat file and restart the PC.