Java command not found - java

I'm trying to get the java command to work on my computer. Whenever I try to use it, I get the error "'java' is not recognized as an internal or..."
What I've done
So far I've traced the issue through my system environment variables, which has a variable PATH that links to "C:\ProgramData\Oracle\Java\javapath" or javapath for short.
There are 3 files in the javapath folder, and if you click on them a popup says:
But when I examine the properties of the shortcut and click "open folder location" it sends me to the right place (?? what is this).
Just in case, I tried to recreate the shortcut; I called it java2 and it now works (opens a command box for a split second and closes) when I click on it. However, testing it in command prompt with the line "java2 -version" returns "'java2' is not recognized as an internal or external..."
Details
I just installed java 8, and I've verified that it was installed correctly
I'm running a 64 bit windows 7 OS

Have you checked your environment variables for Windows? When you installed the JDK/JRE the directory should have been added to the PATH variable. The directory added needs to contain the java.exe executable. It should be located in C:\Program Files\Java or something like that if you installed it using the default settings. Once you find that directory find the bin directory inside it.
In order to check that:
Right click My Computer and hit Properties
On the left side hit Advanced System Settings
Hit the Advanced tab and then Environment Variables down at the bottom
Find the PATH variable and then hit edit. Confirm that the location of the JDK /bin directory is there, if it is not then add it.
Also, if the JAVA_HOME variable isn't already set, this may be a good idea.

Related

Javac working with Powershell but not Command Prompt

I am trying to install Java in Windows 10 Home (64 bit). Like many tutorials point out, I downloaded the Java jdk setup file, executed it and once installed changed the Path in the Environment Variables. But for some reason, when I execute the command 'javac' it returns the not internal/external command error in Command Prompt but runs absolutely fine in Powershell. I tried to rectify this by uninstalling Java and reinstalling it very carefully, following all the steps but still this keeps on happening.
Also, during installation of Java, I lost the original value to my Path variable. Could this be causing the problem?
Edit : I was able to get the java command running in the command prompt but javac still won't work. I've already tried the methods suggested on other forums and this one but no luck so far.
See there is no problem with Java installation if you can find JDK(Java development kit) and JRE(Server Java runtime environment) in programme files in windows in a JAVA folder.
The main problem is with the environment variable declaration.
Go to environment variables and make a new path for that.
JAVA_HOME = "YOUR JDK & JRE INSTALLATION PATH"
And another one is
JAVA = "YOUR JDK & JRE INSTALLATION PATH"
Hope that help to you. After doing that if still there problem persisist just restart your PC and check again.
Just add your variable location up to /bin/
Refer to this :
https://www.windows-commandline.com/javac-not-recognized-internal-external-command/
Open file explorer
Right click computer then click properties
click advanced system settings
click environmental variables
click path (for me there was one in user variables for admin and another in system variables)
find the directory for javac (for me it was here C:\Program Files (x86)\Java\jdk1.8.0_191\bin)
so go back to file explorer and open program files x86
then open the java folder
then open the jdk folder
then open the bin folder
highlight the path in the search bar and copy it
click edit on path and paste into the path in the environmental variable for both(if you have more than one path)
If no path exists then create one in user variables
If there is any existing text place a semicolon ; between the text you pasted in there and the preexisting text.
close command prompt and reopen it.
type javac -version
the version info should be listed
This problem comes up with the directory of your command prompt.
check your PowerShell and command prompt default directory.
We can run command prompt as WinKey+R then type cmd, Hit the enter button then check our java version cmd javac -version.

Java run command not opening

I had installed Java to work with Android Studio. Java works fine on Android Studio but when I try to use Java run command on my computer, it opens and closes immediately. How do I run Java on my computer?
Open command window (cmd on Windows)
Type java -version
You should see the installed java version output.
u need to add this path C:\Program Files\Java\jdk1.8.0_05\bin wheres javac.exe locate copy the path
1. go to System properties then click on advanced system setting .
2. click on Environment variables as picture describe
3. choose the path from system variables and edit it
4. go to end of the line and important to separate between variable values before paste javac.exe path make sure to put semi-colon and paste the path
There is a possibility that you have the following Registry setting configured:
HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System!DisableCMD
If you see the value 'DisableCMD' in the above location then simply delete it.
If you are not comfortable with editing the Registry then you will find this setting by going to:
Start > RUN
Type gpedit.msc and press OK
Navigate to: User Configuration > Administrative Templates > System
Look for the option 'Prevent access to the command prompt'
Double click it and choose 'Not Configured'

Java:System cannot execute the specified program

The javac -version gives the proper version of javac.
But, java -version gives the error as
"System cannot execute the specified program"
The PATH variable is set properly as "C:\Program Files\Java\jdk1.8.0_102\bin"
It is not programming question. But you have to add your %JRE_HOME%\bin to PATH variable
That specific error is likely related to the evaluation of a symlink to the java executables.
Normally, an invalid executable name (meaning, one that is not found in the path) will yield an error with the following text:
'javax' is not recognized as an internal or external command, operable program or batch file.
As you are receiving a different error, this is likely not your issue.
When java is installed on a Windows PC, the installer creates a directory (usually with the path of C:\ProgramData\Oracle\Java\javapath, and places 3 symlinks in it. They are for java.exe, javaw.exe, and javaws.exe. This prevents your path from becoming too cluttered with potentially colliding executable names.
javac.exe (and keytool, etc) work because you added your JRE/JDK bin folder to your PATH. But why does doesn't java/javaw/javaws work? Because it finds the javapath directory above first (PATH is searched left to right). You can see this issue by using the where command. For example:
C:\>where java
C:\ProgramData\Oracle\Java\javapath\java.exe
C:\Program Files (x86)\Java\jre1.8.0_31\bin\java.exe
C:\>where keytool
C:\Program Files (x86)\Java\jre1.8.0_31\bin\keytool.exe
This would be an alright situation, except that the javapath\java.exe symlink is not working, a policy is disallowing its execution, or its path is wrong.
From an administrative command prompt, run the following command. The result should be similar to below
C:\>fsutil behavior query SymlinkEvaluation
Local to local symbolic links are enabled.
Local to remote symbolic links are disabled.
Remote to local symbolic links are disabled.
Remote to remote symbolic links are disabled.
If "Local to local" symbolic links are disabled, that is your problem (as this settings prevents the following reparse points)
You can enable them with the following command:
fsutil behavior set SymlinkEvaluation L2L:1
Double check that the setting changed with the query subcommand. You do not have to restart for this setting to take effect.
If that does not resolve your issue, ensure that the destination of the symlink exists. Try running it via Explorer; a console dialog should pop up then close. If it does not, an easy way to confirm it's correct is to right click the symlink and select "Open File Location". If a error dialog appears stating 'Problem with Shortcut: The item 'java.exe' that this shortcut refers to has been changed or moved [...]', then the path is incorrect.
You can see what the path is set to via the 'Shortcut' tab in the properties of the symlink. If the path is wrong, you can delete the symlink and then recreate it via the mklink command. Delete the symlink and then from an administrative command prompt, run the following; be sure to replace the second path with that of your actual JRE/JDK!
mklink C:\ProgramData\Oracle\Java\javapath\java.exe "C:\Program Files (x86)\Java\jre1.8.0_91\bin\java.exe"
At that point, run 'java' from the command line and see if it works.
If it does not, navigate to your desired java.exe, view its file properties, and ensure there is no "Unblock" button available on the bottom. If there is, click it.
you need to set the PATH variable(jre/bin/) in environment settings.
in cmd , set PATH ="C:/ProgramFiles/java/jre*/bin"

where and how do i save the jdk link so that eclipse will open?

When I go to open eclipse, it gives me a run time error saying that the path to the JDK is not right.
I have no idea where to save the link so that i can get it to open
First Install Java on your pc: It should create Java Folder in C:\Program Files.
You have to set Classpath like this :
Set the CLASSPATH environment variable
(for **Windows NT/2000/XP**)
1. At the left bottom corner of your computer desktop, choose Start -> Setting -> Control Panel, and double-click System
2. On Microsoft Windows NT, select the Environment tab; on Microsoft Windows
2000/XP select the Advanced tab and then Environment Variables.
3. For either User variables or System variables, click New and in the popup window, enter Variable name as CLASSPATH (note that all letters should be capital), and the directory where your JDK is installed as the Variable value.
For example:
If your JDK is installed at: C:\jdk1.4.1_06
Put the following line as the value:
C:\jdk1.4.1_06\bin;C:\jdk1.4.1_06\jre\bin;.
The first is where the java compiler 'javac' is, the second is the java run time environment 'java' is, and the final '.' denotes your working directory, so that the compiler and jre will find where your programs are. To be safe, you may also want to append the above line to then end of your PATH variable. Use ';' as the separator.
Save the variables, test the setting by opening a DOS prompt, type in
echo %CLASSPATH%
If your environment variables are set correctly, you should see your settings.
Or, you can just type in
javac
java
If your PATH and CLASSPATH is correct, windows should recognize those commands.
You do NOT need to restart your computer when installing Java.
Check whether TextPad and Java SDK work on your computer
Download HelloWorld.java into your local drive. Be sure that filename is case sensetive in JAVA programming.
Start TextPad, and open this HelloWorld.java file.
Click menu "Tools" ---> "Compile Java" to compile java file.
Click menu "Tools" ---> "Run Java Application" to run this file.
If you see "Hello World" in a DOS PROMPT window, that means there is no problem with your TextPad to compile/run Java program. Congratulations. You can start your java programming now. If you see some errors when run Java program, please click here to get more information.
For a more comprehensive description on how to setup Java environment on Windows machinese, please refer to the Sun document at: http://java.sun.com/j2se/1.4.2/install-windows.html
For **windows 7**: Follow this link http://www.abodeqa.com/2012/08/11/how-to-set-path/
Then : Start Compatible eclipse (e.g :64bit eclipse on 64bit os).
In Eclipse, select Windows | Preferences
Click the + in front of Java or double-click Java (after the +)
Click Installed JREs
Under the Name column, double-click jre1.5.0_08.
Click the Add External Jars... button.
In the Jar Selection window, navigate to your workspace folder, and double-click the file cs15-1xx.library.
In the Edit JRE window, click OK
In the Installed JREs window, click OK
Terminate (X) the Welcome window
You can always get it back by selecting Help | Welcome
Terminate (X) the Eclipse window.
For more Details follow this : http://blog.ajduke.in/2013/04/28/setting-up-new-java-compiler-and-runtime-in-eclipse-ide/
You can specify the target JRE when launching eclipse by with the -vm command line argument (either through a shortcut or in the eclipse.ini file).
Command line syntax: eclipse -vm c:\jre\bin\javaw.exe
eclipse.ini file syntax (use 2 lines)
-vm
c:/jre/bin/javaw.exe
You can also copy a given version of the JRE under your eclipse installation directory.
Generally speaking I would really advise against adding %JAVA_HOME%/bin to your SYSTEM path. In my experience, this usually leads to many unexpected behaviors. Far better IMHO to set the JAVA_HOME and add its /bin directory to the PATH through scripts/command line/shortcuts/etc. and invoke those when needed.

I'm trying to set my JAVA_HOME path to use my javac.exe?

I'm on Windows 7 and I'm trying to set my JAVA_HOME path to use PhoneGap on android, when i create a project using the command line "cmd" it tells me that it can't find javac.exe? although i'm sure that I've set the variable right
here's my stuff:
Variable name: JAVA_HOME
Variable value: C:\Progra~1\Java\jdk1.7.0_17\bin
(I've also tried to use: C:\Progra~1\Java\jdk1.7.0_17\bin\javac.exe)
My javac.exe location on my laptop C:\Program Files\Java\jdk1.7.0_17\bin\javac.exe
and it still tells me that it can't locate the javac.exe
What I type to create the project and i meet this problem is this:
C:\Users\user>cd C:\Users\user\Desktop\phonegap-2.8.1\lib\android\bin
C:\Users\user\Desktop\phonegap-2.8.1\lib\android\bin>create.bat
Cannot locate javac.exe using the PATH environment variable.
Retry after adding directory containing javac.exe to the PATH variable.
Remember to open a new command window after updating the PATH variable.
Visit http://java.oracle.com if you need to install Java (JDK).
Also, i've tries restarting the windows and closing the command prompt and redownloading the JDK.
Thank You.
cmd is using the values from the PATH variable to locate javac :
set "PATH=%PATH%;C:\Program Files\Java\jdk1.7.0_17\bin"
For other softwares (Tomcat, Maven, etc.) JAVA_HOME must indicate the root of your JDK :
set "JAVA_HOME=C:\Program Files\Java\jdk1.7.0_17\"
No need to restart Windows. When using set the changes are taken immediately.
If you choose to modify those variables in the Control Panel, you have to close and relaunch cmd for the changes to take effect.
You have to add java
C:\Program Files\Java\jdk1.7.0_17\bin
Note that your path may be different.
to your environment variables and restart your console.
You can find how to set your variables here:
http://www.itechtalk.com/thread3595.html
Set the JAVA_HOME Variable
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced system settings. Click the
Environment Variables button. Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit(C:\Program Files\Java\jdk1.7.0_17).
Click OK.
Click Apply Changes.
You might need to restart windows.
Set the JAVA_HOME environmental variable to
C:\Program Files\Java\jdk1.7.0_17
Press
Win + Break > Advanced System Settings > Environment Variables > System Variables
Modify/set JAVA_HOME to the above. (No need to restart)
I already had this error when I tried to create a new phonegap project for android but unfortunately I don't remember how exactly I have fixed this.
I don't know if you have followed the phonegap documentation so here is the link : new project, especially the part 3B (be careful about ; in your PATH).
If you don't know what to do now, maybe you should do it again step by step.
May be a little old, but since this is the first goolge result, I might as well add a little something.
You need to create the JAVA_HOME variable AND edit the PATH variable, adding ;%JAVA_HOME%\bin (with a ;) so cmd and some other apps can actually use javac and the rest of the tools

Categories