Run jar file in command prompt
Try this
java -jar <jar-file-name>.jar
Running JAR file on Windows
Easiest route is probably upgrading or re-installing the Java Runtime Environment (JRE).
Or this:
- Open the Windows Explorer, from the Tools select 'Folder Options...'
- Click the File Types tab, scroll down and select JAR File type.
- Press the Advanced button.
- In the Edit File Type dialog box, select open in Actions box and click Edit...
- Press the Browse button and navigate to the location the Java interpreter javaw.exe.
- In the Application used to perform action field, needs to display something similar to
C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe" -jar "%1" %
(Note: the part starting with 'javaw' must be exactly like that; the other part of the path name can vary depending on which version of Java you're using) then press the OK buttons until all the dialogs are closed.
Which was stolen from here: http://windowstipoftheday.blogspot.com/2005/10/setting-jar-file-association.html
Running a .jar file in a command prompt from double click
This is IMHO not possible. You could open the console from the application itself, but that is OS-dependent. If you need the console open, you have to run the application from it as you already do.
Run a JAR file from the command line and specify classpath
When you specify -jar
then the -cp
parameter will be ignored.
From the documentation:
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
You also cannot "include" needed jar files into another jar file (you would need to extract their contents and put the .class files into your jar file)
You have two options:
- include all jar files from the
lib
directory into the manifest (you can use relative paths there) - Specify everything (including your jar) on the commandline using
-cp
:java -cp MyJar.jar:lib/* com.somepackage.subpackage.Main
Java Windows. why can I run a jar file on command prompt but not double clicking it
You have to tell java to execute your file with javaw.exe
as told by @Carcigenicate
- Start "Control Panel"
- Click "Default Programs"
- Click "Associate a file type or protocol with a specific program"
- Double click .jar
- Browse C:\Program Files\Java\jre7\bin\javaw.exe
- Click the button Open
- Click the button OK
jar file execution from cmd prompt
The problem you're having is that the jar
program is not in your %PATH%
. You may find this answer helpful.
How can I execute .jar file from the terminal without specifying its name
I am not sure it would be a good idea to just run everything in a directory, but you could:
FOR %A IN ("*.jar") DO (java -jar "%~A")
How to include a third-party jar-file in compilation and runtime using command prompt in Windows 10?
The compiled Examp.class
file isn't part of json-20200518.jar
, so you'll need to add the directory containing it to the command line. Assuming it's the current directory (.
):
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar;." com.mypackage.example.Examp
Related Topics
Date Object Simpledateformat Not Parsing Timestamp String Correctly in Java (Android) Environment
Android Changing Floating Action Button Color
How Can One Detect Airplane Mode on Android
Running Shell Commands Though Java Code on Android
How to Paginate Queries by Combining Query Cursors Using Firestorerecycleradapter
Opengl Es2 Alpha Test Problems
Gradle - What Is a Non-Zero Exit Value and How to Fix It
Android: How to Stretch an Image to the Screen Width While Maintaining Aspect Ratio
Onclicklistener Not Responding
How to View My Realm File in the Realm Browser
How to Create a Bks (Bouncycastle) Format Java Keystore That Contains a Client Certificate Chain
How to Update a Textview of an Activity from Another Class
What Is the Size of a Boolean Variable in Java
How to Convert the Following JSON String to Java Object