Running java from console - java

I cannot run the java keyword from the console. What settings do I have to change on XP to get this working.
Thanks in advance.

Install the JVM (or JDK)
Set the JAVA_HOME environment variable to the installation folder
Add the executables location into the PATH environment variable (referencing JAVA_HOME)
Optionally set a CLASSPATH environment variable to have a default classpath

When you install the Sun JRE using its installer, there should be a java.exe file written to %windir%\SYSTEM32. Since this directory is on the PATH, it should be available on the command line.
If you installed Java via some other mechanism, you will have to locate the JRE's bin directory and configure PATH yourself.

right click on computer -> property -> advanced -> environment variable
then choose where save the path:
- in user variable (the path is associated to the user, every other user cannot directly run java, without setting it up).
- in system variable (every user can run java by console without specify the entire path).
choose row with path, double click -> at the end on the line add an ; and then specify the java installation path plus bin...
Exmple:
I installed java in C:\Programs\Java
so I have to put in path C:\Programs\Java\bin\
in Path I had:
%CommonProgramFiles%\Microsoft Shared\Windows Live;%SystemRoot%\system32
after modification I'll have
%CommonProgramFiles%\Microsoft Shared\Windows Live;%SystemRoot%\system32;C:\Programs\Java\bin\

Related

Javac not recognised even after setting variable path, Windows 10?

I'm getting an error when typing javac in command prompt.
C:\Users\HP>javac
javac is not recognized as an internal or external command, operable program or batch file.
C:\Users\HP>set path
path=C:\Program Files\Java\jdk-10\bin;C:\Program Files\Java\jre-10\bin\javaw.exe;C:\Program Files\Java\jdk-10\bin;C:\Program Files\Java\jre-10\bin;
PATHEXT=C:\Program Files (x86)\Documents;
I have already set Path in both system and user scope environment varible?
You may set 2 system variable from console:
set JAVA_HOME="c:\Program Files\Java\jdk1.8.0_144"
set PATH=%JAVA_HOME%\bin;%PATH%
then your command "javac" will be found.
The PATH variable looks corrupted. Moreover, the PATHEXT variable is totally confused. Their default value in Windows 7/10/2008 (assuming the system drive is C:) should be as follows:
PATH C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem;{plus program paths}
PATHEXT .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH; .MSC
Check output from SET PATH in a freshly open cmd window. If path and pathext look as above then use (modify directory names to match current Java version):
set "JAVA_HOME=C:\Program Files\Java\jre-9.0.4"
set "PATH=%JAVA_HOME%\bin;%PATH%"
Above setting is temporary (would last only for current cmd session). For persistent solution, there are more tutorials on the net e.g. How To Set Java Path & Java Home Variables (Windows, MacOS, Ubuntu).
Try out the following solutions.
Close your current cmd and Open a new cmd.exe
Restart the computer
NOTE: If cmd is open when you set the environment variables, then, that property will not be available until unless you open new cmd.
On Windows 10, the problem of 'javac is not recognized ...' can be fixed in these 4 steps:
Step 1: Install JDK to specific path (Example: C:\jdk-15)
Step 2: Setup JAVA_HOME environment variable to the installation folder
Windows --> Advanced settings --> Environment variables --> System Variable
--> Add new variable
JAVA_HOME = C:\jdk-15
Step 3: Prefix JAVA_HOME\bin to PATH variable of Windows
Windows --> Advanced settings --> Environment variables --> System Variables
--> Update PATH variable
PATH = JAVA_HOME\bin;..... old value of PATH variable ....
Step 4: Try the javac and java commands in new command window
Note: Already opened command windows will not take the new values of JAVA_HOME or PATH. The test needs to be done in new window opened after the environment variables are changed and saved.
C:\Users\user1> javac -version
C:\Users\user1> java -version

Run a jar file only with jre [duplicate]

When trying to check the current version of Java in which I am running, I received the error "java is not recognized as an internal or external command, operable program or batch file.".
I am running Windows 7 OS and have downloaded the latest JDK and felt I may have accidentally deleted the java from machine as before I was able to check the Java version using the command "java -version".
What software must I download to get Java working on my machine again?
EDIT:
I have managed to get Java running from my cmd again after ensuring all environment variables pointed to the current Java SDK.
You need to configure your environment variables, JAVA_HOME and PATH.
JAVA_HOME must contain the path to java, and you should add %JAVA_HOME%\bin to PATH
Alternatively, you can simply add to your PATH the whole path to the bin folder, without the JAVA_HOME variable, however, this makes a little more annoying when you need to have more than one java version on your machine (that way you only need to change JAVA_HOME and don't even bother with PATH)
For Windows 7:
Right click on My Computer
Select Properties
Select Advanced System Settings
Select the Advanced tab
Select Environment Variables
Select Path under System Variables
Click on the Edit button
In Variable value editor paste this at the start of the line
C:\Program Files\Java\jdk1.7.0_72\bin;
Click Ok then Ok again
Restart command prompt otherwise it won't see the change to the path variable
Type java -version in the command prompt.
Notes on Step 8:
The version of java in this may be different from the one used here -- this is only an example.
There will probably be other values in the path variable. It is really important that you don't delete what's already there. That's why the instructions say to paste the given value at the start of the line -- this means that you don't remove the existing value, you just put java before it. This also fixes any problems you'd be getting if an other version of java is also on the path.
Notes on Step 6:
This sets the path for the computer, not for the individual user. It may be that you're working on a computer which other developers also use, in which case you'd rather set the user variables, rather than the system variables
It sounds like you haven't added the right directory to your path.
First find out which directory you've installed Java in. For example, on my box it's in C:\Program Files\java\jdk1.7.0_111. Once you've found it, try running it directly. For example:
c:\> "c:\Program Files\java\jdk1.7.0_11\bin\java" -version
Once you've definitely got the right version, add the bin directory to your PATH environment variable.
Note that you don't need a JAVA_HOME environment variable, and haven't for some time. Some tools may use it - and if you're using one of those, then sure, set it - but if you're just using (say) Eclipse and the command-line java/javac tools, you're fine without it.
1 Yes, this has reminded me that I need to update...
Assume, Java/JDK is installed to the folder: C:\Program Files\Java:
Follow the steps:
Goto Control Panel → System → Advanced system settings → Advanced → Environment variables (Win+Pause/Break for System in Control Panel)
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\bin, press OK:
In the System variables section double click on Path
Press New and write C:\Program Files\Java\bin, press OK:
In Environment variables window press OK
Restart/Run cmd.exe and write: java --version:
Search environment variables.
open the "edit the system environment variables".
then click on "environment variables".
Under "User variables" click on "Path" then "Edit".
Find your Java path and click "Edit".
then paste the path of your java installation folder.
Mostly you can find it on a path similar to this.
C:\Program Files\Java\jdk-12.0.2\bin
Then click OK.
now in the start menu, type cmd.
open the command prompt.
type
java -version
If you did it right,it should show something like this.
For me its start working after putting ,: in the starting of the system variable path :--
My solution was to put same value (path to JDK bin folder) in JAVA_HOME and Path
In my case, PATH was properly SET but PATHEXT has been cleared by me by mistake with .exe extension. That why window can't find java or anything .exe application from command prompt. Hope it can help someone.
This problem is on Windows 8.
First copy your Path of java jdk - e.g. C:\Program Files\Java\jdk1.7.0_51\bin.
Right on the My Computer Icon on the Desktop and Click Properties.
Select 'Advanced System Settings' in the left pane.
Under 'Advanced' tab, select 'Environment Variables' at the bottom.
In System Variables, select 'Path' Variable and edit it.
Paste the path and add a ';' at the end - e.g. C:\Program Files\Java\jdk1.7.0_51\bin;
I had the same problem. Just Install the exact bit of java as of your computer. If your PC is 64 bit then install 64 bit java. If it is 32 bit then vice versa :)
Not sure why, but in my case, the reason was because I was running Anaconda terminal instead of the CMD.
After I use CMD and update the path settings as mentioned by all comments above the issue solved on my side.
In case you are using a laptop and do not have the Pause\Break button.
For windows 10 users with 20h2 and above:
1 WIN → type "About your PC" → scroll at the bottom → Advanced system settings → Environment variables or WIN+R → shell:::{bb06c0e4-d293-4f75-8a90-cb05b6477eee} to open Classic System Properties → on the left side → Advanced system settings → Environment variables
Also for Windows 10 and Windows 7:
1 WIN → This PC → properties → Advanced system settings → Environment variables
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\jdk-15.0.2\bin, press OK
I have taken steps 2-4 from Vijay Bhatt
There is a bit faster way to set a system variable. Run a console (terminal) as an administrator.
General command synax to add a new variable:
setx variableName value /M
In our example, we would need to set it as
setx JAVA_HOME "C:\Program Files\Java\jdk-15.0.2\bin" /M`
Like this:
/M - flag specifies to set the variable in the system environment.
After command execution, you should see the message:
SUCCESS: Specified value was saved.
How can I check that it is added?
Close your active terminal;
Open your favorite terminal;
Type java -version.
You should see something similar to this:
Notice:
User variables can be created w/o having a root (administrator privileges), whereas to create System variable; You need to open a console as a root.
I have used C:\Program Files\Java\jdk-15.0.2\bin as an example, in your case, it could be different from mine.
I opened a new command prompt in Windows 10 after updating the environment variables without closing the old one(To have my commands handy and lazy to type again)
Still, the new cmd window was referring to the previous version of Java.
Then once I closed the all cmd prompts that ran with admin privileges, the new java version was getting reflected.
I corrected my path variable but command prompt need to Restart otherwise, it won't be able to verify the change to the path variable. May be helpful for someone like me. so
"restart command prompt"
Restart the command prompt before checking the version of JDK installed. I spent 02 days on it until my problem resolved when I restarted the command prompt before checking javac - version, javac etc.
if you have cygwin installed in the Windows Box, or using UNIX Shell then
Issue bash#which java
This will tell you whether java is in your classpath or NOT.
If you have set the environment variables (JAVA_HOME and PATH) under user variables, command prompt (run as administrator) will not identify java. For that you need to set environment variables under system variables.
Try this:
System variables:
PATH = /bin folder of your jdk install
https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-microsoft-windows-platforms.htm
Just some extra information for people that have still problems,
instead of editing the path variable of java, delete that part of the path(only the java!!)
and make a new variable pointing tpo the jdk/jre.
this seemed to work for me.

Javac is not found

I'm running Windows 8 and I can not get javac to work.
I have set my PATH in environmental variables to
C:\Program Files (x86)\Java\jdk1.7.0_17\bin
I have tried both with and without ';' but to no avail.
I recently had this issue on my desktop and adding ; worked but it's not in this case.
I have made sure that javac does exist in the bin too.
Any suggestions on fixes would be greatly appreciated.
EDITS
echo %PATH% gives:
C:\Users\Arktri\Desktop>echo %PATH%
C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;
C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;
C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;;
C:\Program Files (x86)\Java\jre7\bin
And the exact error is: 'javac' is not recognized as an internal or external command, operable program or batch file.
As far as I can see you have the JRE in your PATH, but not the JDK.
From a command prompt try this:
set PATH=%PATH%;C:\Program Files (x86)\Java\jdk1.7.0_17\bin
Then try javac again - if this works you'll need to permanently modify your environment variables to have PATH include the JDK too.
Go to my computer;
Right click properties;
Go to advanced system settings;
Go to environment variables;
In user variables for user click on new(top new button, not on system variables);
Set variable name as: Path
Set the value of that variable to: C:\Program Files\Java\jdk1.7.0_76\bin
Click ok;
Click ok;
Click ok.
Now you're set. Type javac in cmd. All javac options will be displayed.
EDIT: As #MediaMaker pointed out, after completing the above steps, you need to open a new command prompt for it to work.
Easiest way: search for javac.exe in windows search bar. Then copy and paste the entire folder name and add it into the environmental variables path in advanced system settings.
I'm searched many answers that suggest me to type in cmd:
set path = "%path%;c:program files\java\jdk1.7.0\bin"
but this is WRONG!
the right solution is that you leave "set" and just type
path = %path%;c:program files\java\jdk1.7.0\bin
P/s: of course you have to replace "jdk1.7.0" folder by your current java version folder. This works well on win 7 32bit, but I think it also works on win 8 - try it!
Start off by opening a cmd.exe session, changing directory to the "program files" directory that has the javac.exe executable and running .\javac.exe.
If that doesn't work, reinstall java. If that works, odds are you will find (in doing that task) that you've installed a 64 bit javac.exe, or a slightly different release number of javac.exe, or in a different drive, etc. and selecting the right entry in your path will become child's play.
Only use the semicolon between directories in the PATH environment variable, and remember that in some systems, you need to log out and log back in before the new environment variable is accessible to all environments.
You don't have jdk1.7.0_17 in your PATH - check again.
There is only JRE which may not contain 'javac' compiler.
Besides it is best to set JAVA_HOME variable, and then include it in PATH.
do this:
1. run CMD (WIN+R then type in CMD)
2. Type this:
set PATH=%PATH%; java installation path\bin
Replace "java installation path" with the directory JDK is installed in, such as C:\Program Files (x86)\Java. Be sure to add the \bin after the JDK directory, because this points to "javac" and "java" (BIN stands for "binaries")
This way, you can run the Java compiler from anywhere. It is impossible to CD to the JDK directory because it has a space in Program Files, and DOS will not let you CD to these directories.

How to set the java path and classpath in windows-64bit

I have installed java on windows-64bit OS. but when I execute javac, it is failing with the
error message no such command is available". I have created following environmental variable
CLASSPATH C:\Program Files (x86)\Java\jdk1.6.0_05\lib
Add the appropriate javac path to your PATH variable. java.exe will be found under the bin directory of your JDK. E.g.
SET PATH=%PATH%;C:\Program Files (x86)\Java\jdk1.6.0_05\bin
Before answering your question, just wann ans this simple question : Why we need PATH and CLASSPATH?
Answer:
1) PATH: You need to set PATH to compile Java source code, create JAVA CLASS FILES and Operating System to load classes at runtime.
2) CLASSPATH: This is used by JVM and not by OS.
Answer to your question :
Just make sure you have Modified PATH variable (Windows System Environmental Variable) so that it points to bin dir which contains all exe for example: java,javac and etc. In my case it is like this : ;C:\Program Files\Java\jre7\bin.
So, it doesn't matter your system is 32 bit/64 bit until and unless you specify/Modify the PATH variable correctly.
Actually, the most conventional way of getting it done on Windows is
Go to Control Panel
Click System
Open Advanced settings
Click Environment Variables...
Path is one of the variables under "System Variables".
This is where the system will search when you try to execute a command.
just append the full path to the Bin folder under your Java
installation path. You can copy it using Windows Explorer to avoid typing it manually
click OK to close the dialogs.
To verify, open the command window aka console window (for example, WindowsKey-R cmd.exe ) and run:
javac -version
If the java bin folder is in the path, the system will find and execute the javac.exe file located there, and you will see your Java version. Something like:
c:\>javac -version
javac 1.7.0_65
Very Simple:
You need to set the two environment variables only; PATH and java
=>Right Click on My computer
=>Properties
=>Click on left hand side bar menu "Advanced system settings"
=> Click on "Environment Variables" button refer below fig.
=>Follow the below steps to Set User variable and System variable.
To Set User variable named as "PATH"
Click on "New" button in user variables section.
Set the variable name as "PATH" and variable value as per your java
installed version.(Shown in below fig.)
To Set System variable named as "java"
Click on "New" button in System variable tab.
Set the variable name as "java" and variable value as per your java
installed version.(Shown in below fig.)
Refer below images for the reference.
For me, the 'JAVA_HOME' variable should be set as a System Variable, instead of User Variable.
When the 'JAVA_HOME' was changed to be a System Variable, the command 'javac' works.
Also, the PATH and CLASSPATH are System Variable.

How do I add `java` to the command path on Vista?

I have JDK installed in Vista. I want to run java from the command line. How do I configure the path variable?
If I'm not able to set the JAVA_HOME variable, what is an alternative?
Open My Conputer -> General Settings -> Environment variables and add as global
Key:JAVA_HOME
Value:C:\jsdk etc. etc.
And then modify the Path variable
Value ( type at the end )
....something;something;something;%JAVA_HOME%\bin
Reopen your command prompt and type
javac
And see if it works
EDIT
Moved my comment to the answer
The command prompt has some problems dealing with the empty space.
What I usually do is install the jdk directly on C: to get rid of space in "Program Files"
So installing it directly in C: will give you an "spaceless" path to the executable:
C:\jdk1.6.0_14\bin\javac
Instead of
C:\Program Files\Java\jdk1.6.0_14\bin\javac
Some times you'll get: C:\Program "executable not found" or something like that.
Installing directly on C: does the trick
I'd suggest looking at the java tutorial.
http://java.sun.com/docs/books/tutorial/essential/environment/paths.html
CLASSPATH manual
Running java from the command line
If the java program is available in your path then you should just be able to do;
c:> java -classpath somedir com.example.Main
if java isn't available to you then you can do
c:> SET JAVA_HOME=c:\path\to\java
c:> <same java stuff from above>
Use the -classpath option for the java command to specify where your classes are.
The value of the classpath option is a list of directories, JAR archives, and ZIP archives that contain classes, structured into directories that mirror the classes' package structure. The list uses the path delimiter, which is plaform specific: on Windows, it is ";", other platforms use ":".
Using the CLASSPATH environment variable is discouraged because changes for one program are likely to interfere with the operation of other programs.
There is some problem with Vista and the path variable containing %JAVA_PATH% if the JAVA_PATH value has spaces.
I fixed this manually by setting the %JAVA_PATH% to c:\program files\Java\<whatever> and then added to c:\program files\Java\<whatever>\bin to the Path variable in Vista.
If you deleted your My Computer icon, you can also go to Control Panel -> System -> Advanced system settings (which gives you System Properties dialog) -> Advanced tab -> Environment Variables. Path is listed in the second text window.

Categories

Resources