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
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
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.
Short trick: after I only REMOVED SPACES from names of the folders, where the .jar file was, double-clicked worked and the file executed.
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
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.
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.