How to run jar file on windows

How to run a JAR file on Windows 10 [QUICK GUIDE]

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

A JAR file is a Java archive package format that might include a Java program within it. While you can extract JARs with archive software such as 7zip, you can’t run a pure Java JAR app as you would with other programs in Windows.

Since that’s the case, we’ll cover how you can run a pure Java app JAR file in Windows.

How can I run a JAR file on Windows 10?

1. Add Java to Windows

The crucial thing you need upfront is to have Java installed. Without it, Java apps aren’t going to run in Windows. This is how you can install or update Java in Windows 10:

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

2. Download a JAR file opener

You can open JAR files and hundreds of different formats with a single application. File Viewer Plus is a universal file viewer for Windows that can open and display over 300 different file types.

The new updated version has a plethora of features that will save you big time on opening, viewing, or editing files.

File Viewer Plus supports the most popular text, audio or video file type, as well as archive, source code or web files.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

File Viewer Plus

3. Use Java(TM) Platform SE binary

4. Run a JAR file from the Windows Command Prompt

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

That will open the executable JAR file so long as it contains a manifest file to specify the application’s entry point. (The developers should have already included that in the archive.)

If you develop your own Java programs, you’ll need to convert the JAR to an executable format.

5. Add a third-party JAR executor to Windows

If you’re having trouble accessing the JAR file or you get some kind of an error, take a look at this nifty guide to finding some great fixes.

With all this, you can now run JAR files in Windows. If you need to fix a JAR file that isn’t opening, check out this Windows Report guide.

If you have any other suggestions or questions, leave them in the comments section below and we’ll be sure to take a look.

Источник

How to run a JAR file

I created a JAR file like this:

I ran this JAR file by double clicking on it (it didn’t work). So I ran it from the DOS prompt like this:

It raised «Failed to load main class» exceptions. So I extracted this JAR file:

and I ran the class file:

It worked well. I do not know why the JAR file did not work. Please tell me the steps to run the JAR file

11 Answers 11

You need to specify a Main-Class in the jar file manifest.

Oracle’s tutorial contains a complete demonstration, but here’s another one from scratch. You need two files:

Note that the text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.

Before run the jar check Main-Class: classname is available or not in MANIFEST.MF file. MANIFEST.MF is present in jar.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

You have to add a manifest to the jar, which tells the java runtime what the main class is. Create a file ‘Manifest.mf’ with the following content:

Change ‘your.programs.MainClass’ to your actual main class. Now put the file into the Jar-file, in a subfolder named ‘META-INF’. You can use any ZIP-utility for that.

Executing the jar file. No need to worry too much about manifest file. Make it simple and elgant.

Java sample Hello World Program

Compiling the class file

Creating the jar file

Running the jar file

If you don`t want to create a manifest just to run the jar file, you can reference the main-class directly from the command line when you run the jar file.

This sets the which main-class to run in the jar file.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

If you don’t want to deal with those details, you can also use the export jar assistants from Eclipse or NetBeans.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

Eclipse Runnable JAR File

Create a Java Project – RunnableJAR

Run Jar file using java program (cmd) by supplying arguments and get the output and display in eclipse console.

Help ► Help Contents ► Java development user guide ► References ► Menus and Actions

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

I have this folder structure:

D:\JavaProjects\OlivePressApp\com\lynda\olivepress\Main.class D:\JavaProjects\OlivePressApp\com\lynda\olivepress\press\OlivePress.class D:\JavaProjects\OlivePressApp\com\lynda\olivepress\olives\Kalamata.class D:\JavaProjects\OlivePressApp\com\lynda\olivepress\olives\Ligurian.class D:\JavaProjects\OlivePressApp\com\lynda\olivepress\olives\Olive.class

Main.class is in package com.lynda.olivepress

There are two other packages:

1) Create a file named «Manifest.txt» with Two Lines, First with Main-Class and a Second Empty Line.

2) Create JAR with Manifest and Main-Class Entry Point

D:\JavaProjects\OlivePressApp> jar cfm OlivePressApp.jar Manifest.txt com/lynda/olivepress/Main.class com/lynda/olivepress/*

Note: com/lynda/olivepress/* means including the other two packages mentioned above, before point 1)

Источник

How To Run A JAR File On Windows

Windows apps are mainly packaged as installers or executable files. An app installer has the MSI extension and an executable file has the EXE extension. At times, a developer may choose to zip an EXE file. This is done because browsers will block an EXE from downloading thinking it is malicious. Similarly, some email services and clients may not let users attach or download an EXE file. Windows users are therefore, used to extracting an EXE from a zipped folder in order to run it. While normal, this can be confusing if you’ve downloaded a JAR file. The JAR file will be associated with the 7zip or Winzip apps. The archive app will be able to extract the JAR file but there isn’t going to be anything in it that you can run. Here’s how you can run a JAR file on Windows.

What Is A JAR File?

A JAR file is a Java file. JAR is the file extension for Java files. Apps are built to run on the JAVA framework. Minecraft (the desktop version) is one common example of an app that requires Java installed on your system to run. Minecraft itself is packaged as an EXE file so you never have to run a JAR file with it.

The JAR file is a pure Java app that hasn’t been packaged into an EXE. Windows alone cannot run it.

Install Java

In order to run a JAR file on Windows, you need to install Java on your system. Check if the file you want to run requires a specific version of Java to run. If the developer hasn’t specified a version, download and install the latest version of Java on your system.

Run A JAR File

The file association of the JAR file will not change once you’ve installed Java. Go to the folder the JAR file is in. Right-click it and go to the ‘Open with’ option. Select ‘Choose another app’. You will see ‘Java(TM) Platform SE binary’ listed in this context menu but don’t select it. Select the ‘Choose another app’ option.

The file will now open. All future JAR files that you download will now be associated with Java. You will only have to double click a JAR file to run it. The next JAR file you download will not be associated with an archive app. Instead, the file’s icon will be the official Java file icon.

4 Comments

Have you at any time made too much money without trying to sell a thing or perhaps left out engaging in any of the mlm kind of job and one never has to make investments anything at all. Let me discuss a task wherein pretty much all specialty tools will be alloted to you and additionally it truly is an easy and also very simple gig. No need to launch your websites for example., all are generally provided to you free of charge. Customers will definitely take a look at your site so you will immediately get paid for that. It really is as easy as that. Now I am creating some huge cash from a home office because of this work just like 20000 dollars month to month or more if you also genuinely wish to receive like this so therefore follow these specific relatively simple instructions by exploring this web page >>>>> ADULTADDA.NET/2Yw

Have you made some huge cash without trying to sell things or rather left out working at any specific referral marketing sort of business while not having to make an investments any-thing. I wish to tell you a task whereby all of the software is generally given to you and also its quite a simple in addition to so easy work. No need to setup your personal websites and etc., everything are going to be provided to you at absolutely no cost. People definitely will log in your website therefore you will get remunerated for that. It really is as simple as that. I’m taking home a substantial amount of money from home through this project exactly like 20000 dollars month-to-month and more if you might actually want to take home money like this so therefore follow all these easy to understand tips by viewing this internet site >>>>> OLAURL.COM/15cp9

Have you in any case attained a ton of money without reselling a thing and even left out spending time on any direct sales kind of work and not having to make investments anything at all. I wish to discuss a project whereby every ways are generally presented to you and as a consequence its a very easy in addition to quite simple venture. Its not necessary to make your very own domain names and all that., almost all are generally made available to you free. Everyone will take a look at your web blog and you are able to get remunerated for that. Its as easy as that. Now I am creating large sums of money at home using this task such as 20 thousand bucks month to month and sometimes more just in case you might actually want to make money same as that then follow these specific incredibly easy information by viewing this web-site >>>>> SHRTY.LINK/YqgLBM

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Источник

Run a Java Application from the Command Line

Last modified: December 7, 2019

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

If you have a few years of experience in the Java ecosystem, and you’re interested in sharing that experience with the community (and getting paid for your work of course), have a look at the «Write for Us» page. Cheers, Eugen

1. Overview

Typically, every meaningful application includes one or more JAR files as dependencies. However, there are times a JAR file itself represents a standalone application or a web application.

We’ll focus on the standalone application scenario in this article. Hereafter, we’ll refer to it as a JAR application.

In this tutorial, we’ll first learn how to create a JAR application. Later, we’ll learn how to run a JAR application with or without command-line arguments.

2. Create a JAR Application

A JAR file can contain one or more main classes. Each main class is the entry point of an application. So, theoretically, a JAR file can contain more than one application, but it has to contain at least one main class to be able to run.

A JAR file can have one entry point set in its manifest file. In this case, the JAR file is an executable JAR. The main class has to be included in that JAR file.

First of all, let’s see a quick example of how to compile our classes and create an executable JAR with a manifest file:

A non-executable JAR is simply a JAR file that doesn’t have a Main-Class defined in the manifest file. As we’ll see later, we can still run a main class that’s contained in the JAR file itself.

Here’s how we would create a non-executable JAR without a manifest file:

3. Java Command Line Arguments

Just like any application, a JAR application accepts any number of arguments, including zero arguments. It all depends on the application’s need.

This allows the user to specify configuration information when the application is launched.

As a result, the application can avoid hardcoded values, and it still can handle many different use cases.

An argument can contain any alphanumeric characters, unicode characters and possibly some special characters allowed by the shell, for example ‘@’.

Arguments are separated by one or more spaces. If an argument needs to contain spaces, the spaces have to be enclosed between quotes. Either single quotes or double quotes work fine.

Usually, for a typical Java application, when invoking the application, the user enters command-line arguments after the name of the class.

However, it’s not always the case for JAR applications.

As we have already discussed, the entry point of a Java main class is the main method. The arguments are all Strings and are passed to the main method as a String array.

That said, inside the application, we can convert any element of the String array to other data types, such as char, int, double, their wrapper classes, or other appropriate types.

4. Run an Executable JAR with Arguments

Let’s see the basic syntax for running an executable JAR file with arguments:

The executable JAR created earlier is a simple application that just prints out the arguments passed in. We can run it with any number of arguments. Below is an example with two arguments:

We’ll see the following output in the console:

So, when invoking an executable JAR, we don’t need to specify the main class name on the command line. We simply add our arguments after the JAR file name. If we do provide a class name after the executable JAR file name, it simply becomes the first argument to the actual main class.

Most times, a JAR application is an executable JAR. An executable JAR can have a maximum of one main class defined in the manifest file.

Consequently, other applications in the same executable JAR file can’t be set in the manifest file, but we can still run them from the command line just like we would for a non-executable JAR. We’ll see exactly how in the next section.

5. Run a Non-Executable JAR with Arguments

To run an application in a non-executable JAR file, we have to use -cp option instead of -jar. We’ll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute:

As you can see, in this case, we’ll have to include the main class name in the command line, followed by arguments.

The non-executable JAR created earlier contains the same simple application. We can run it with any (including zero) arguments. Here’s an example with two arguments:

And, just like we saw above, we’ll see the following output:

6. Conclusion

In this tutorial, we learned two ways of running a JAR application on the command line with or without arguments.

We also demonstrated that an argument could contain spaces and special characters (when allowed by the shell).

As always, the code for the examples is available over on GitHub.

Источник

How do I run a Java program from the command line on Windows?

I’m trying to execute a Java program from the command line in Windows. Here is my code:

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

12 Answers 12

Let’s say your file is in C:\mywork\

Run Command Prompt

This makes C:\mywork the current directory.

This displays the directory contents. You should see filenamehere.java among the files.

This tells the system where to find JDK programs.

This runs javac.exe, the compiler. You should see nothing but the next system prompt.

javac has created the filenamehere.class file. You should see filenamehere.java and filenamehere.class among the files.

This runs the Java interpreter. You should then see your program output.

If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command. Java is case-sensitive!

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

To complete the answer :

Compile the Java File to a *.class file

Execution of the Java File

Creation of an executable *.jar file

With an external manifest file :

The MANIFEST file is nothing but an explicit entry of the Main Class

Executable by Entry Point:

To run the Jar File

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

Compile it in the usual way:

But to run it, you need to give the package name and then your java class name:

Complile a Java file to generate a class:

Execute the generated class:

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

Assuming the file is called «CopyFile.java», do the following:

The first line compiles the source code into executable byte code. The second line executes it, first adding the current directory to the class path (just in case).

Since Java 11, java command line tool has been able to run a single-file source-code directly. e.g.

This was an enhancement with JEP 330: https://openjdk.java.net/jeps/330

For the details of the usage and the limitations, see the manual of your Java implementation such as one provided by Oracle: https://docs.oracle.com/en/java/javase/11/tools/java.html

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

It is easy. If you have saved your file as A.text first thing you should do is save it as A.java. Now it is a Java file.

Now you need to open cmd and set path to you A.java file before compile it. you can refer this for that.

Then you can compile your file using command

So that is how you compile and run a java program in cmd. You can also go through these material that is Java in depth lessons. Lot of things you need to understand in Java is covered there for beginners.

You can compile any java source using javac in command line ; eg, javac CopyFile.java. To run : java CopyFile. You can also compile all java files using javac *.java as long as they’re in the same directory

If you’re having an issue resulting with «could not find or load main class» you may not have jre in your path. Have a look at this question: Could not find or load main class

On Windows 7 I had to do the following:

quick way

long way

This likely breaks when you upgrade your JDK installation but you have access to all the command line tools now.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *