I just installed Oracle JDK 11 on my Windows 10. I noticed that the PATH variable doesn't include the JDK 11 path. Also the .JAR file extension is not associated with javaw. Our users used to doubleclick JAR file to execute the client Java/SWING application. With Java 11 this doesn't work. Is this a bug or feature? I know how to set the PATH and start the application manually using the command line. I just want to make it easier for end-users. Any ideas?
There is no Public JRE in Java 11, as there was in the previous Java versions. Don't be confused with the jre directory in previous JDK version, it's not a Public JRE. Also installers of the old Public JRE copied the java.exe and the javaw.exe programs into the C:\Windows\System32 directory that is defined in the PATH environment variable by default. They also did many other thing, like changes in your Windows registry. Installers of the old Public JRE had never changed anything in the PATH.
Official alternative to the Public JRE is a custom runtime environment that you can built by the jlink tool of the JDK. However in this case you will have no jar file at all but UNIX shell and Batch scripts.
If you don't like it you may use JDK 11 and associate the jar files in Windows Explorer with javaw.exe of JDK, instead of JRE, as described there Running JAR file on Windows
Open regedit.exe
Select HKEY_CLASSES_ROOT
Create new key .jar
Type jarfile to default value
img
In HKEY_CLASSES_ROOT create new key jarfile
In jarfile create key tree like
jarfile
DefaultIcon
shell
open
command
[Optional] Type path to icon/executable file to default value in DefaultIcon
Type path to javaw.exe to default value in command like "C:\Java\jdk11\bin\javaw.exe" -jar "%1"
img
Now select javaw.exe when opening the program.
I made a bat file, which contains the following:
java -jar %1
Click on a jar > open with > select your bat
If java path is set correctly (check with java -version) it will run your jar after double clicking.
Related
I have the JDK 10.0.2 installed, have the cmd opened in the folder of the class files of my program and try the command: javap Simulation.class .
I get the error that the command javap is not found. What do I do wrong?
You must have your $JAVA_HOME/bin directory added to system PATH for javap command to be available without it's absolute path.
Alternatively you can call javap using the absolute path:
/usr/lib/.../bin/javap Simulation.class
Assuming you are on Windows, check in your environment variable PATH whether path to Java executables is set.
Ex. If you have installed Java on path,say, C:\Program Files\Java\jdk-10
Then you have to add C:\Program Files\Java\jdk-10\bin to your PATH environment variable to be able to execute java commands from anywhere on command line.
References for Oracle Docs
https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-microsoft-windows-platforms.htm#JSJIG-GUID-DAF345BA-B3E7-4CF2-B87A-B6662D691840
https://www.java.com/en/download/help/path.xml
On a sidenote, recommend you to move to Java 11 or 17 now that Java 10 is no longer supported. The above instructions would still remain same.
append $JAVA_HOME/bin to system $PATH variable. for example on linux
JAVA_HOME= "path of java installation on system"
export PATH = $JAVA_HOME/bin:$PATH
Open the control panel and type envir in search bar.
Click on edit the system environment variables.
Click on environment variables in the advanced system properties.
Click on path mentioned in user variables.
Edit the path, and click new and paste the path of java jdk.
In my system, the path is C:\Program Files\Java\jdk-17.0.2\bin, it could be different for your system.
Click ok, the problem must be solved now.
Running a .jar file in the command line works fine, but I am unable to execute .jar files on my PC by double-clicking them. What is interesting, the same .jar files successfully execute on my laptop with a double-click.
I included %JAVA_HOME\bin and JDK_HOME\bin in the PATH variable.
I have JAVA_HOME set to C:\Program Files\Java\jre1.8.0_121.
I have JDK_HOME set to C:\Program Files\Java\jdk1.8.0_121.
For some period of time, the Java(TM) Platform SE binary disappeared from the Open with list, and I could not add it until I changed the HKEY_CLASSES_ROOT\jar_auto_file\shell\open\command key in regedit.exe to the appropriate version:
C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe" "%1".
Here is a snapshot of Windows CMD with java -version entered on my PC:
I tried the following methods, with no success:
reinstalling both JRE and JDK,
associating .jar files with C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe,
using assoc .jar=jarfile and ftype jarfile="C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe" -jar "%1" %* in command line,
creating a new system Environment Variable OPENDS_JAVA_ARGS and setting it to -jar.
Additional information:
I am using Windows 7 Professional 64-bit (Service Pack 1) with latest
updates installed both on my PC and laptop.
Running .jar files by double-clicking them used to work on my PC,
but suddently stopped working some time ago. I did not modify
anything related to Java.
I have the newest version of both JRE and JDK (Java 8 version 121).
Of the .jar files I am trying to run, some are GUI Swing applications
and some open the system console (if not already open) using
Runtime.getRuntime().exec(String[]).
I have already tried fixing this problem with solutions on the following links (without success):
How to run .jar file by double click on Windows 7 (64)
How to open/run .jar file (double-click not working)?
I can run .jar files through cmd, but I cannot double click them
Can't Run JAR Files
Notes:
I do not want to open .jar files with WinRAR.
I do not want to open .jar files by running java -jar jarfile.jar in cmd.exe.
I am not looking for a 3rd party application to run .jar files.
For now, I am using C:\Windows\System32\cmd.exe /k "java -jar C:\path\to\jarfile\Program.jar" as a shortcut location to run jar files, but I am not satisfied with this solution as this opens the console to run even Swing applications.
I managed to get Java(TM) Platform SE binary (javaw.exe) in the Open with list by matching paths in HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE registry entries:
HKEY_CURRENT_USER\Software\Classes\jar_auto_file\shell\open\command
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell\open\command
Seems like one of the entries pointed to an older version of Java. Now .jar files are finally showing icons, but still do not work on double-click.
UPDATE: SOLUTION
Delete the .jar and jar_auto_file entries from HKEY_CURRENT_USER/Software/Classes and it should work. .jar files should open on double-click again.
Make sure to backup these entries first by right-clicking the entry and choosing Export.
Additional information can be found on superuser.
I am trying to set java path on my windows 8.1, and i installed jdk 8u 64 bit and in environmental variables under system variables there is no PATH found,so i incuded new path variable to set path for jdk and jre ,by copying the bin path of jdk C:\Program Files (x86)\Java\jdk1.8.0_40\bin and i appended jre path C:\Program Files (x86)\Java\jre1.8.0_40,but it doesnt work when i tried in command prompt by typing "java -version"
and "javac" it says that java is not a internal or external command. and i had a doubt that to run java through command prompt ,do we need any other installations like turbo c
please help me out to set path in my pc,i am a begginer of java
thank you
javac is not part of jre, but part of jdk. So have C:\Program Files (x86)\Java\jdk1.8.0_40\bin;C:\Program Files (x86)\Java\jre1.8.0_40\bin in the path. As Anand noted, the ; is missing as well.
This path is wrong -
C:\Program Files (x86)\Java\jdk1.8.0_40C:\Program F iles
(x86)\Java\jre1.8.0_40\bin
you need a ; in between the two different paths.
Try adding this instead -
C:\Program Files (x86)\Java\jdk1.8.0_40\bin;C:\Program F iles
(x86)\Java\jre1.8.0_40\bin
If you are trying to add the path in the user variables
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_66
in the JAVA_HOME don't add any semicolan (;) and
path=C:\Program Files\Java\jdk1.8.0_66\bin;.;
in the path section end of the line add ;.; to consider all paths and save. Then try to restart system and open the command prompt and try to check
java -version
javac
JAVA_HOME AND PATH
I've been learning java on my own and I've come to a point where I need to pass arguments from the command prompt. I had previously been using Netbeans, which has become a bit of a crutch, but I want to learn how to program using notepad and the command prompt. I am running Windows 8.1. I downloaded the JDK 7 to my C:\ directory. I tried typing "java -version" and "javac -version" to check it out (as my book says to do) but it tells me "'java' is not recognized as an internal or external command, operable program or batch file." It says the same when I try javac. I do this from C:\ and from C:\Java> and get the same result. I uninstalled Netbeans, thinking maybe it was interfering somehow ... still not working. The book I'm using says it covers Java 7.
I don't understand why it doesn't work. Is there some compatibility issue with Java 7 and win 8.1? My java 7 is update 71 or 72. Did this update change something and now arguments are passed differently? Can anyone help me out? Thank you.
You need to download the JDK (if you don't already have it) and add the location to the end of your PATH. In a single command line session you can do this with PATH=%PATH%;<jdk location> where <jdk location> is the bin folder of the jdk.
Some installs of java manage environment variables and some do not. It appears yours has not. or you have not installed it correctly.
many applications understand JAVA_HOME, so you should set that to the root of the installation in your environment variables.
You will also need to add the bin folder to your path.
Generally, when using windows, you can install a windows exe version, which will manage all of this for you. Other installations just copy themselves to the c drive and expect java applications to know where to look.
Go to System environment variable. Select Variable PATH. Click on edit button. Append a ; after current value of Variable value. Copy jdk's bin folder path. In my PC it is "C:\Program Files\Java\jdk1.8.0_20\bin" without quotes. Then paste jdk's bin path. Copy jre's bin folder path. In my PC it is "C:\Program Files\Java\jdk1.8.0_20\jre\bin". Append a ; then paste jre's bin folder path. Click OK.
Download the JDK from this page. Run the installer.
Open the Command Prompt. Try it. It works. Yay!
If you use the full path to your java.exe, you dont need to set up any PATH and JAVA_HOME:
c:\> cd \work
c:\work> c:\java\bin\java.exe -cp classes\ your.Main
If your book does not use the normal JDK installers it really is supposed to explain that. (However it is normal behaviour for any executable).
(The above example asumes you compile into c:\work\classes\your\Main.class and your JDK is installed (installer does the unpack) in C:\java (typically you would use default locations like C:\Program Files\Java\jdk1.8.0\bin\java.exe).
I downloaded this Java JDK and installed it.
But when I go to the command prompt to check the version, it says it's not recognized.
Is anyone else experiencing this issue with the latest Java?
I might not have installed the right version. I need the java that works with grails
C:\>java
'java' is not recognized as an internal or external command,
operable program or batch file.
C:\>java -version
'java' is not recognized as an internal or external command,
operable program or batch file.
C:\>
when i do a search on my computer for java, it does not find anything
Windows 2k8 R2 server-
For both java [-option] or %JAVA_HOME% to work in the command line you need the following:
In Control Panel->System and Security->System->Advanced system setting->Advanced->Environment Variables->System Variables
Edit the Path variable and add a ";" after the last value and add the the path to the Java bin directory:
e.g.- C:\Progra~2\Java\jre6\bin\
Add the JAVA_HOME Variable with the value set to the path for the java executable:
e.g.- C:\Progra~2\Java\jre6\bin\java.exe
Press simultaneously the "windows" and "pause" buttons on your keyboard, this will bring up the System Preferences dialog.
In the Advanced tab, find Environment Variables.
Then, in the User (upper) section, create or update the following two variables :
JAVA_HOME = where you put your JDK, eg. C:/Java/SDK
PATH = %JAVA_HOME%/bin
Close the dialogs.
Then, in a new command-line console, try "javac -version" and see if it's detected.
It's important that you use a new console, because environment variables are read only when the console is launched.
Java is typically installed (on Windows) as C:\Program Files\Java\jdk<version>
That installation directory has a subdirectory bin which you need to append to your PATH environment variable via the control panel. Then, the commands like java, javac etc. will be available on the command line.
BTW, the same is true for Grails.
Is the -version flag not recognized, or is the "java" command not recognized? One way to test this is just to type 'java' by itself and run it and see what happens.
If the command is not recognized, make sure that the JDK's install path is in your windows PATH. If not, you won't be able to use any of the java executables from the command prompt. Here's another link that may help out.
You need to manually add the path to javac.exe and java.exe to your operating system path. The Java installation program doesn't do that for you.
You most likely don't have java.exe in your system's PATH variable.
For Linux:
check $PATH and $JAVA_HOME. You can configure it in /etc/environment
From console you can check it like:
$ echo $PATH
For Windows:
My Computer -> Properties -> Advanced -> Environment Variables
Check there PATH.
From console you can check it like:
echo %PATH%
You should have a Java icon in Windows Control Panel. Locate the Java tab and click the View button. That will show you the path to the Java executables.
Last but not least, make sure you have restarted the computer so changes in the PATH variable can take effect.
You installed the JDK. Isn't java.exe part of the JRE? Do you have that installed?
Maybe your system variables in the environment variables are not set properly. Follow the steps in the link below. Finally, make sure the path component in system variables has only one JDK path. Delete other JDK paths that you won't use.
https://docs.oracle.com/javase/tutorial/essential/environment/paths.html
You might have installed a previous or older version of Java so you can just uninstall it and directly download JDK from Java JDK
I was also facing the same issue but when I downloaded and installed the latest version the issue was resolved.
Also uninstall any other Java versions which may be present in the program files.
To get to know other versions which may be present in your computer use Windows File Explorer to go to:
Files > Windows C > Program Files > Java
All the JDK and JRE you have will be listed there. Uninstall any other Java versions other than what you installed. And then make sure you have set the path variable of the JDK.
For me, it was incorrect line in the PATH
(1) Check PATH: Type "Edit System Environment Variables" on the search -> System Properties -> Advance -> Environment Variables -> System variables -> Path
(2) On the list, mine was C:\Program Files (x86)\Common Files\Oracle\Java\javapath so I just add \ at the end (the exe files in the javapath folder)
OS: Windows 10 64 bit
IF you set the PATH and it's not showing up in cmd when you run %PATH%, try restarting your computer.