How to make the jar file executing after being double clicked - java

I have the next problem - my .jar file works when I invoke it from the command line as java -jar name.jar
But it does not start when I double click on it on the desktop of my Windows 7...
Moreover, when I try to start it with clicking the right buttonof the mouse "open with" and choose Java(TM) SE platform binary it does not start either
How to make it start with the double click?

Apparently the .jar extension is not associated with javaw.exe on your computer.
To do this, run the following two commands in a commandline window:
ftype jarfile="C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*
assoc .jar jarfile
(Adjust the path to javaw.exe to your installation path)
You should run this with an account that has administrative privileges as this will update the globel registry.
Edit (after the comments):
As Java7 is not yet that widespread, you should re-compile your sources using the compiler switch -target 1.6 or compile them using Java6 right from the start. The your jar file should also with Java6

Related

My java program runs in netbeans, but will not run in command or through the jar file. What am I doing wrong?

So, I am trying to run a program from jar files. It uses javaswing and has a gui.
The program runs fine in netbeans and in eclipse.
When I try to run it from the exported jar file it says this:
Unable To Install Java
There are errors in the following switches:
"C:\Users\CNC Department\Desktop\ValveConversion.jar";.
Check that the commands are valid and try again.[java installation not complete
Now, I also tried doing it from the command prompt. Here is what came up:
[cmd prompt attempt][1] [1]: https://i.stack.imgur.com/7reZ3.png
So, I reinstalled the java JDK, java SDK, netbeans and eclipse. The issue is still occurring in both command prompt and from running the jar file directly.
What am I doing incorrectly here? What do you recommend that I do to get this to run from a .jar file?
You need to set the java path
Open a cmd with elevated privileges and run this command to set the JAVA_HOME environment variable using setx command:
setx JAVA_HOME -m "C:\Program Files\Java\jdk-11.0.2"
Then restart the cmd and run java -version to check if it's all ok.
For reference setx command documentation
Or simply use the following snippet if you prefer to use java without setting the PATH variable:
"C:\Program Files\Java\jdk-11.0.2\bin\java" -jar "C:\Users\CNC Department\Desktop\ValveConversion.jar"

Oracle JDK 11 installer & JAR file association on Windows

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.

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.

Unable to run .jar files by double-clicking them on Windows 7

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.

jar file is not executing on double clicking on windows 7

I have CQ5 executable jar file.It is suppose to be executed on double clicking.But i get error saying "could not find Main class program will exit".The same jar file executed on all my team mates machine but i am unable to execute it.
I am working on windows 7 OS.
I have jre6 installed.
I have done all steps provided in following link .jar file keeps giving me " could not find the main class". Program will exit.
my ftype and assoc is set to propervalue.
there is no problem in manifest file(becoz it executed on others machine).
all my path variables are set properly.
type of file on my system is "JAR" but on everyone else machine its "Executable JAR"
Could not figure out what is problem with my system.
Help plz.
You can alternatively try executing this command from a command console,
first CD to the location where you have the jar file and execute
For Win7 32-bit:
java -Xmx1024M -jar .jar
For Win7 64-bit:
java -XX:MaxPermSize=256m -Xmx1024M -jar .jar
if you have supported version of Java installed correctly, then the command should be able to start the CQ5 server. In that case, for fixing the double click issue, you would need to fix the filetype association of .jar files to open with /bin/javaw.exe
For supported Java versions, refer
CQ5.5 http://dev.day.com/docs/en/cq/5-5/deploying/technical_requirements.html
CQ5.6 http://dev.day.com/docs/en/cq/5-6/deploying/technical_requirements.html

Categories