How to open/run .jar file (double-click not working)? - java

I can't open or run my .jar file.
I just installed java, but I tried to open the .jar with other programs first, so the double-click defaults to something else and I can't change it back.
java -jar myfile.jar`
Above command returns:
'java' is not recognized as an internal or external command, operable program or batch file.
Is there a way I can still open/run this?
e: OS is Windows 8.
Also, I downloaded the .jar file; didn't create it myself (if that's relevant)
Not sure if it contains an executable (but I think it does).

you can use the command prompt:
javaw.exe -jar yourfile.jar
Hope it works for you.

There are two different types of Java to download: The JDK, which is used to write Java programs, and the RE (runtime environment), which is used to actually run Java programs. Are you sure that you installed the RE instead of the SDK?

Use cmd prompt and type
java -jar exapmple.jar
To run your jar file.
for more information refer to this link it describes how to properly open the jar file.
https://superuser.com/questions/745112/how-do-i-run-a-jar-file-without-installing-java

You may have several JDKs installed in your PC. Some older JDK installers also copy some java files such as java.exe, javaw.exe into C:\Windows\System32 folder.
I had a similar issue, and searched the internet for a solution and none of the suggestions didn’t open by double clicking the .jar file.
In my case the reason is I have multiple JDK & JRE versions installed on my computer. Since I am a software developer working with several different versions for different clients I need to use multiple JDKs in my PC (Windows 10 Pro). So I do not want to change the system variables (i.e. JAVA_HOME, JRE_HOME or PATH), instead I use command prompt to run java in user process whenever I wanted to use a different version.
When installing JDK it registers the .jar file association with latest version we installed in the PC. If you right click on the .jar icon and select properties, it will show that file opens with “Java(TM) Platform SE Binary”. If we look at the registry key: HKEY_CLASSES_ROOT\jarfile\shell\open\command, it will point to latest JDK version.
It is not a good idea (sometimes annoying) to change the registry key every time I want to run an app build from a different version.
So in my situation it is impossible to just double click the .jar file to execute it. But instead I found a work around solution myself.
Scenario:
Multiple JDKs (1.7, 1.8, 9.0, 10.0, 11.0, and 12.0)are installed in the PC, so the latest installed was 12.0.
Problem
Want to double click an executable .jar developed using JDK 1.8 and didn’t work
This is my work around solution:
Create a shortcut for the .jar file that you want to open.
Right click the shortcut icon and select properties -> Shortcut tab
Change the text in the target (for example "D:\Dev\JavaApp1.8.jar")
To
"C:\Program Files\Java\jdk1.8.0\bin\javaw.exe" -jar
"D:\Dev\JavaApp1.8.jar"
Then click ok Double click the shortcut.
It should now open the app.

I was having this same issue for both Windows 8 and Windows Server 2012 configurations.
I had installed the latest version of JDK Java 7 and had set my **JAVA_HOME**system env variable to the jre folder: *C:\Program Files (x86)\Java\jre7*
I also added the bin folder to my **Path** system env variable: *%JAVA_HOME%\bin*
But I was still having problems with double clicking the executable jar files. I found another system env variable OPENDS_JAVA_ARGS that can be used to set the optional properties for javaw.exe. So I added this variable and set it to: -jar
Now I am able to run the executable jar files when double clicking them.

In cmd you can use the following:
c:\your directory\your folder\build>java -jar yourFile.jar
However, you need to create you .jar file on your project if you use Netbeans. How just go to Run ->Clean and Build Project(your project name)
Also make sure you project properties Build->Packing has a yourFile.jar
and check Build JAR after Compiling
check Copy Depentent Libraries
Warning: Make sure your Environmental variables for Java are properly set.
Old way to compile and run a Java File from the command prompt (cmd)
Compiling: c:\>javac Myclass.java
Running: c:\>java com.myPackage.Myclass
I hope this info help.

Go to your java directory,
Copy this path
C:\Program Files\Java\jdk1.8.0_40\bin
Right click on my computer , click properties, then go to "Advanced system settings"
click , Environment variables.
go to "System variables" table, find an entry named "path".
Double click it and go to the end, put a semicolon and paste your path, apply and ok.
It should run now.

first of all, we have to make sure that you have downloaded and installed the JDK.
In order to download it click on the following link
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
(Do not forget to check "Accept License Agreement", before you choose the version you want to download)
For Windows OS 32-Bit (x86) choose "jdk-8u77-windows-i586.exe"
For Windows OS 64-Bit (x64) choose "jdk-8u77-windows-x64.exe"
Install the file that is going to be downloaded. During the installation, pay attention, because you have to keep the installation path.
When you have done so, the last thing to do, is to define two "Environment Variables".
The first "Environmental Variable" name should be:
JAVA_HOME
and its value should be the installation path
(for example: C:\Program Files\Java\jdk1.8.0_77)
The second "Environmental Variable" name should be:
JRE_HOME and its value should be the installation path
(for example C:\Program Files\Java\jre8)
As soon as you have defined the Environment Variables, you can go to command prompt (cdm) and run from every path your preferred "java.exe" commands. Your command line can now recognize your "java.exe" commands.
:)
P.S.: In order to define "Environment Variable", make a right click on "This PC" and select "properties" from the menu. Then the "System" window will appear and you have to click on "Advanced system settings". As a consequence "System properties" window shows. Select the "Advanced" tab and click on "Environment Variables" button. You can now define the aforementioned variables and you're done

You must create a manifest file and specify your class that has the main method. you can build your jar file with manifest file as a parameter.
jar cfm MyJar.jar Manifest.txt MyPackage/*.class
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Cakes
Build-Jdk: 1.6.0_04
Main-Class: com.foo.App

An easy way to execute .jar files is to create a batch file.
Let's say you placed your jar file on your Desktop;
#echo OFF
java -jar C:\Users\YourName\Desktop\myjar.jar
Copy this code to a .txt file, modify "YourName" and save as "myjar.bat". Then whenever you double click, the jar file will be executed.
Hope this helps.

Short trick: after I only REMOVED SPACES from names of the folders, where the .jar file was, double-clicked worked and the file executed.

In Netbeans please delete current you create the jar file and on the project explore of Netbeans please clean and build 2 or 3 times and right the project folder in project explore and build the jar file.

I had this problem a while back and the solution was really easy.
Just uninstall the current version of Java, download an older one, then uninstall the older and install the latest again.
For example: Java 8 Update 73 current install Java 7 Update 95.
How it works: Java's registry keys were messed up, and when you install the older version they get fixed.

If the intention of the question is to view the contents of the JAR file, then the following java command would help.. (provided, JDK location is added to the environment variables.)
Windows Command prompt> jar tvf yourJarFile.jar
Example:
jar tvf log4j-extras-1.2.17.jar
Reference: http://docs.oracle.com/javase/tutorial/deployment/jar/view.html

I downloaded the latest JDK 7u10. Once you do that, try running your jar, It should execute.

Related

How to set Eclipse Java version in OS X

When I download and expand Eclipse EE version a file of type Application is created :
I'm new to using to Eclipse on MAC. I want to set the java version to
export JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
But no eclipse.ini file is created. How to set and or install Eclipse on MAC and set the java version ?
This solution allows you to specify the JVM for a given eclipse installation, without changing any system properties. Make sure you have a valid JVM (usually JDK 8 for eclipse) installed.
Here are the steps:
open finder and navigate to the location of Eclipse (i.e. Applications)
right-click on the eclipse application
select "show package contents"
navigate to /content/Eclipse/eclipse.ini
open the .ini with a text-editor
at the top of the file, add the following lines (or replace the existing -vm line)
-vm
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin
You need to replace adoptopenjdk-8.jdk with the name of your JVM.
File type "Application" is actually a directory. Right-click it (or control click) and select "Show Package Contents". You should find eclipse.ini at Contents/MacOS/eclipse.ini inside the Eclipse application directory.
You need to install the full JDK rather than the JRE before you can use it with Eclipse. The full JDK should set itself as the current Java. The JDK installs in something like /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home
As mentioned in the other answer the Eclipse application is actually a directory (called Eclipse.app) using 'Show Package Contents' in Finder will show you the contents.

Executable jar doesn't start normally

I created an executable jar file with eclipse indigo, but when i double click on it nothing happens. But when i write java -jar c:/dir/filename.jar to cmd, it works. Other jars runs well. I'm using jdk 1.7.0_02 and eclipse indigo. How could i start it normally?
You can run a jar by double clicking it, you just have to make sure that Java is associated with .jar files. The easiest way to do this is by reinstalling the JRE (which generally does it for you).
Otherwise you will need to modify some of your Windows properties (I'm not sure what version of Windows you are running) to point .jar files to the instance of javaw.exe.
Here's a link to a Windows 7 page on how to do it.
right click on .jar file and go to properties, then set "open with" program to "Java SE Binary".
You can do this by associating the .jar extension with the command to run it via javaw.exe.
"C:\Program Files\Java\{java version}\bin\javaw.exe" -jar "%1" %*

Executable JAR on Ubuntu (NetBeans)

I'm writing a simple Swing application in NetBeans and doing so on an Ubuntu machine for the first time.
As many of you know, NetBeans automatically creates executable JARs for projects that are "set as main".
On Windows, you can double-click an executable JAR and it automatically invokes the JRE and runs the app. In Ubuntu, double-clicking the .jar file causes the file to be opened in the archive manager instead. In order to run my JAR, I either have to right-click it and select "Open with OpenJDK Java 6 Runtime" or launch it from the command line.
From the command line I get no problems whatsoever. However, when I try launching it from the right-click menu, I get an error that reads:
The file MySwingApp.jar is not marked as executable...
So I have 2 questions:
What do I have to do to set it as executable? Is this something I can do inside NB or do I have to use the shell? If I have to set permissions via the shell, doesn't that conflict with NB's policy of auto-generating **executable** JARS? And what command would I use to flip the executable bit anyhow?!?!
Is this just a Linux hiccup? I want to send this JAR to friend who run Windows and I'd like for them to be able to just double-click it and have the program launch
Thanks for any helpful suggestions!
You will need to manually tweak your build process to get the jar file marked as executable in Netbeans. Go to your project root and open build.xml. The header has instructions on adding to the build process. There is a target, "-post-jar", that is called after the jar is built. You'll need to make that target and use Ant's chmod task to modify your jar. Once you do that it will occur every time you make a jar file in that project.
It will run fine on your friend's Windows machine, as long as he has a JRE installed.
Here is a thread about running jars using double click in Linux.
You can Java like a native binary on Ubuntu (and other linuxes), it's a feature of the kernel. You need to install the binfmt-support package to give the kernel the hooks to run java in this way.
In Ubuntu open up a terminal and run:
sudo apt-get install binfmt-support
Then make your JAR file executable
chmod a+x yourjar.jar
Then you can run your JAR like any other binary by typing
yourjar.jar
Jar-files aren't first class executables, and they don't become magically executables by changing their executable flag.
If you execute a jar, you run the command
java -jar YOURJAR.jar ...
It's the same, as if you double click a png file, and expect it to run in a painting program
gimp YOUR.png
You don't need to make your png an executable one, and it will not solve a problem.
Instead, you have to tell your desktop environment, what to do when double clicking a jar or png-File, and you have to do it on Linux the same way you do it in Windows - maybe the installer on Windows does it for you, because there is normally just on Desktop Environment (Windows) on the OS (Windows), but Linux has Gnome, KDE, XFCE, LXDE, fluxbox and millions more.
And it isn't so sure what you want to do with it. Since jar-files are a special form of packed zipfiles, usually containing a Manifest and the classes, the Archivmanager isn't a false solution, and it is saver to show the content of the archive, than executing it.
Copying the file to windows has no effect. Windows not even has an executable flag, but you shouldn't fiddle with it though. You change your desktop settings, and those can't be moved to windows, and you will not want to.
And if you have the correct settings in your DE, you don't need to tell Netbeans or any other IDE repeatedly, what to do with jar-files.
I gone through Internet and I came across one article with complete steps to run jar file
http://mlartist.blogspot.in/2012/07/deployment-netbeans-project-in-linux.html
Jar files are basically a zip file, to create an executable, you have several different methods. The Best (in my opinion) is to use ant to create it. Or you can simply echo "Main-Class: YOUR.MAIN.CLASS" >> Manifest and then create your jar by jar -cmf Manifest JARFILENAME.jar INPUTFILES then, to make it executable under linux, right click on it and click on properties. Then click on permission tab and check execute. or you can be a terminal bamf and cd to the jar directory and chmod +x JARFILE.jar
HAPPY NIXING!!

jar to exe convert problem

hi i converted my jar file into an exe using jsmooth but when i install it, it shows an error like java not found.
Please help me, how can I add the jre to my exe wrapper so this problem is solved.
It is trying to get the java installation to run your application, where it might be searching in JAVA_HOME, So if the JAVA_HOME is not set in the machine where you installing your application then try to install the java and set the JAVA_HOME as a pre-requisite of your installation.
I don't believe JSmooth can actually bundle a JRE with the exe. What you can do is tell JSmooth where to expect the JRE when running the exe (as in the same folder the exe is run from). If you do this you simply need to zip the exe and a JRE up, and distribute that.
The end user would unzip this, and the resulting folder would contain your exe and the JRE. Since JSmooth knows where to look relative your exe, it can find the JRE.
i have use it using launch4j
follow the following steps
1-create project directory called e.g:project
2-copy the runnable jar file to it
3-copy the jre directory to it u can rename it or keep name as it e.g i will call myjre
run launch4j program :
1- fill the basic tap with required information .
2- go to JRE tap there is a field called (bundle JRE path ) write "myjre" add min Jar virsion 1,6 it will case you an error if you do not fill this fields
and then click run button to generate exe file , you have to remember to keep the myjre directory with along side with executable exe file
e.g the application directory should contains :
1- [you app name].exe
2-myjre
in this description you can run your application with no care if jre is installed in a machine or not and become portable
Good Luck , feel free to contact me for more details

JSmooth question on bundling a JRE

I'm trying to bundle a JRE with my jar file so that I can run my application on any windows computer, regardless of if it has Java or not. The jsmooth manual says:
For the option to work correctly, you have to put a JRE in a directory near the EXE (generally in a subdirectory called "jre" or whatever). Once the exe is generated, it will FIRST try to locate the JRE at the location mentioned. If it can't be found there, then it will fallback in the normal jre look-up mode (search for a jre or a jdk in the Windows registry or in commonly-used environment variables). There is no JVM-version check when using a bundled JRE, as the packager is supposed to bundle a suitable JVM for the application.
Does this mean that the jre subfolder should be included in the jar, be its own separate jar, or put in the folder that comes along with the exe? If it is supposed to be in a folder with the exe, how can I specify the relative path to the jre subfolder?
My directories are as follows:
setup/
-jre/
-myprogram.exe
I tried using ..\jre, .\jre, ..\setup\jre in the GUI screen, but none of them worked.
Any ideas or leads would be greatly appreciated. Thanks so much!
EDIT: when I tried jre (and ..\jre I think), I got the following error message from windows when I tried running it "MyProgram.exe has stopped running." When I look at the problem details, it says APPCRASH and the fault module name is jvm.dll
just put the "jre" folder next to the exe, and write "jre" (without quotes) in the GUI of jsmooth
As an alternative, I would suggest using the mature open source project, NSIS. You could write an installer that would download and install the JRE, and then create shortcuts to run your program.
Here are some useful links:
http://nsis.sourceforge.net/Simple_Java_Runtime_Download_Script
http://nsis.sourceforge.net/Java_Launcher
Have you tried Launch4J (http://launch4j.sourceforge.net/), we switched from JSmooth to this a while ago, as it was more up to date and had more features.
But, put the jre folder in the same folder as the .exe, then use jre\ as the path to it. You'll need to make sure the working folder of the .exe is the installation folder though. And make sure you have a full JRE in the jre folder.

Categories