Folder to jar windows

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

  • To run a JAR file on your Windows 10 device you certainly need to have Jave installed.
  • You’ll find below a path to the latest Java version in case you need it.
  • Then, you can find JAR file openers or executors, and we recommend some.
  • Using Command Prompt is also a handy solution if you don’t want to install third-party tools.

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:

  • First, open Command Prompt(Admin) by pressing the Win key + R keyboard combination and entering cmd in the box.
  • Next, input java -version in the Command Prompt and press Enter. It will then provide further details on your Java version as below.

  • The current version of Java is Version 8 Update 131. If you don’t have Java or the most up-to-date version, you can add it for free.
  • Run through the Java setup wizard. Then, open your browser to verify that the program is working.

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.

File Viewer Plus

3. Use Java(TM) Platform SE binary

  1. Open the File Explorer and the folder that includes the file you need to run.
  2. You should right-click the JAR file and select Open with from the context menu.
  3. Click Choose another app and then select to open it with Java(TM) Platform SE binary.
  4. Click the Always use this app to open JAR files check box.
  5. Press the OK button to close the menu.
  6. Now you can run the selected JAR, and all other JARfiles will also be associated with Java.

4. Run a JAR file from the Windows Command Prompt

  1. Press the Win key + X hotkey and select Command Prompt (Admin) to open it as administrator.
  2. Then input the following command (replacing the example with the actual path of the file you need to run) and press Enter: java -jar c:pathtojarfile.jar
  3. Alternatively, you can open the folder that includes the JAR in the Command Prompt first by entering cd / followed by the directory. Then, you can input java -jar file.jar without the folder path.

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

There are also executor programs for Windows that enable you to run JAR files the same as any other program . Jarx is one of them and you can add it to Windows by clicking Jarx-1.2-installer.exe on this page.

Click the jarx .exe to run the software, which doesn’t really have a GUI as such (except an About jarx window). Then you can double-click the JAR files to run them in 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.

Читайте также:  Windows амалды ж йесіні рамына андай браузер кіреді жауаптары

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 turn folder into jar — Code

Hi im busy on a application that decompiles a jar the pastes files into the folder of the decompiled jar, it then compresses the folder into a jar.

Decompiling and copying works, but i can’t manage to get the folders contents to be jared (compressed into jar), i did about 3hrs research and found only outdated methods. please help.

EDIT MORE INFO: I apologize i mean i cant get my application to turn a folder into a jar file, my application is an modification installer for a jar file. and it extracts the jars files, then adds the modification and then, is supposed to then turn the folder back into a jar file so that the modification is installed. The jar file is not executable.

9 Answers 9

Given that you want to create the JAR through code; you can use JarOutputStream for that. There is an example at this link that contains code to create a JAR file given a File[] containing all the input files.

As for creating the list of files given a starting input path, see Recursively list files in Java.

You could either build a list of files then just use code like in the above example, or you could recursively scan files and add them to the JAR as you go.

If you are using Java 7 and you know your users are too you can also use Files.walkFileTree() with a FileVisitor that adds entries to the JAR as it visits files.

Original answer before OP clarified:

Is there something wrong with:

The JDK comes with a jar utility to create JAR files.

You can read an official tutorial on it here: Creating JAR Files. It is very straightforward.

If you want to create a runnable JAR, you can create a manifest file that has the main class and other options in it. The linked tutorial describes that process.

Including all the jars in a directory within the Java classpath

Is there a way to include all the jar files within a directory in the classpath?

I’m trying java -classpath lib/*.jar:. my.package.Program and it is not able to find class files that are certainly in those jars. Do I need to add each jar file to the classpath separately?

25 Answers 25

Using Java 6 or later, the classpath option supports wildcards. Note the following:

  • Use straight quotes ( » )
  • Use * , not *.jar

Windows

Unix

This is similar to Windows, but uses : instead of ; . If you cannot use wildcards, bash allows the following syntax (where lib is the directory containing all the Java archive files):

(Note that using a classpath is incompatible with the -jar option. See also: Execute jar file with multiple classpath libraries from command prompt)

Understanding Wildcards

From the Classpath document:

Class path entries can contain the basename wildcard character * , which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR . For example, the class path entry foo/* specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.

A class path entry that contains * will not match class files. To match both classes and JAR files in a single directory foo, use either foo;foo/* or foo/*;foo . The order chosen determines whether the classes and resources in foo are loaded before JAR files in foo , or vice versa.

Subdirectories are not searched recursively. For example, foo/* looks for JAR files only in foo , not in foo/bar , foo/baz , etc.

The order in which the JAR files in a directory are enumerated in the expanded class path is not specified and may vary from platform to platform and even from moment to moment on the same machine. A well-constructed application should not depend upon any particular order. If a specific order is required then the JAR files can be enumerated explicitly in the class path.

Expansion of wildcards is done early, prior to the invocation of a program’s main method, rather than late, during the class-loading process itself. Each element of the input class path containing a wildcard is replaced by the (possibly empty) sequence of elements generated by enumerating the JAR files in the named directory. For example, if the directory foo contains a.jar , b.jar , and c.jar , then the class path foo/* is expanded into foo/a.jar;foo/b.jar;foo/c.jar , and that string would be the value of the system property java.class.path .

The CLASSPATH environment variable is not treated any differently from the -classpath (or -cp ) command-line option. That is, wildcards are honored in all these cases. However, class path wildcards are not honored in the Class-Path jar-manifest header.

Running JAR file on Windows

I have a JAR file named helloworld.jar. In order to run it, I’m executing the following command in a command-line window:

Читайте также:  Starting windows event viewer

This works fine, but how do I execute it with double-click instead? Do I need to install any software?

25 Answers 25

Easiest route is probably upgrading or re-installing the Java Runtime Environment (JRE).

  • 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.

In Windows Vista or Windows 7, the manual file association editor has been removed.

The easiest way is to run Jarfix, a tiny but powerful freeware tool. Just run it and your Java apps is back. double-clickable again.

If you need to distribute your .jar file and make it runnable at other people’s Windows computers, you can make a simple .bat file like this in the command prompt:

and place the .bat file in the same directory as your .jar file.

If you have a jar file called Example.jar, follow these rules:

  1. Open a notepad.exe
  2. Write : java -jar Example.jar
  3. Save it with the extension .bat
  4. Copy it to the directory which has the .jar file
  5. Double click it to run your .jar file

An interesting side effect of this causes a problem when starting runnable jar files in the command prompt.

If you try (in a command prompt):

No joy, because this is being translated to the following (which doesn’t work):

However, the following command does work:

If you change the association in file manager as described above to:

Then you can type:

in the command prompt and it will now work!

EDIT:(However you then get a black console window when you run a form based (non console) Java app, so this is not an ideal solution)

If you run these jar files by double clicking them in windows, no parameters will be passed so your Java code needs to handle the stack overflow exception and include a «press a key» function at the end or the window will just disappear.

In order to pass a parameter in windows you have to create a shortcut to the jar file, which includes the parameter in the target line (right click on the shortcut and select properties) you can not add parameters to the jar file icon itself in this way.

There isn’t a single, consistent solution here, but you would have the same problem with any other console application.

There is a windows freeware application called «bat to exe» which you can use to create an exe file from a .bat file with the apropriate command line in it. you can also embed the jar file in the exe with this application, and make it clean it up when it has finished running, so this may be a more elegant solution.

www.makeuseof.com

Follow MUO

How to Open JAR Files in Windows 10

Have you ever come across the JAR file type? Here’s what a JAR file is and how to open JAR files in Windows 10.

A JAR file is a Java Archive file. It’s used to package Java files and metadata together into a single file. If you want to know how to open a JAR file in Windows 10, you’ve come to the right place. We’re going to explain what JAR files contain and how to open them.

You might also encounter errors when trying to open a JAR file. We’ve got you covered with solutions for that too.

What Is a JAR File?

JAR stands for Java ARchive. As the name suggests, it’s an archive file. This means that it’s a single file containing other files packaged together for reasons such as portability and decreased storage space.

If you’re familiar with ZIP files, then a JAR file is essentially the same thing. The difference is that JAR files are applications designed to be used by the Java Runtime Environment.

The unique element of JAR files is that they contain a manifest. This is a special meta-file that, simply put, tells the JAR how to behave and holds information about the files within.

A JAR file can also contain CLASS files (compiled Java code), audio files, image files, and more. The JAR file can then be read and run as a single request by the Runtime Environment.

JAR can be used for all sorts of purposes on desktop and mobile. For example, it could be a game, application theme, or browser add-on.

How to Open JAR Files

If you want to execute a JAR file—that is, run the actual application contained within—then you need to install the Java Runtime Environment. You may already have it on your computer but grab it again from the official site to ensure you’re running the latest version.

Читайте также:  Get the mac address linux

You should then download a lightweight utility called Jarx. This makes JAR files behave like ordinary programs on your computer. As such, once Jarx is installed, you can then open a JAR file like any other.

You can also run it from Command Prompt. Press Windows key + X and click Command Prompt (Admin). Then input the following command, but replace sample.jar with the full file path of the JAR:

How to Extract a JAR

Alternatively, you can unpackage the JAR file. You can do this to see what files are contained within it or if the JAR file isn’t designed to be an executable file.

To unpackage a JAR, you need a program that can extract compressed files. Windows includes functionality for this, but you can also use file extraction software like 7-Zip or WinRAR to get the job done.

Open the JAR file within the software, and you can browse all the folders and files within it. You can also extract the JAR if you want to use or inspect the individual files further.

Alternatively, you can use an online extractor if you don’t want to download an extracting program. A good choice is Archive Extractor because it’s easy to use and, most importantly, supports JAR files (not all online extractors do).

Simply upload your JAR, and it will show you the contents of the file within a tree structure. Click a folder to open or expand it and a file to download it individually.

Finally, if your computer is having problems recognizing an executable JAR file, you can right-click the file, click Rename and then append the .ZIP file extension. This works because the file types are so closely linked.

How to Make JAR Files

Are you sure you need to make a JAR file? Remember, they serve a specific purpose: bundling files together to be used as a Java application.

If that’s what you need to do, head over to Oracle’s packaging programs in JAR files documentation. This will give you all the information you need on how to create, package, and sign a JAR file.

How to Fix Problems Opening JAR Files

You might get an error when trying to open a JAR file, often due to incompatibility or security settings.

Update the Java Runtime Environment

You should always run the latest version of the Java Runtime Environment.

To see what version of Java you’re running, open the Start menu, type configure java, and select the result. The Java Control Panel will open.

On the General tab, click About and check that the version you’re running aligns with the latest one available directly from Oracle’s website. If not, download it and update it.

JAR Opens in the Wrong Program

Windows might not know what to do with the JAR file and could try to open it in a program that won’t support the format.

To resolve this, right-click the file, and hover Open with. There are several default programs to choose from, and one of these might be the right one. If not, click Choose another app.

You can change Windows 10’s file associations and default programs if you want JAR files to always open in the same program.

If you want to run the file within the Java Runtime Environment directly:

  1. Navigate to Program Files\Java.
  2. Open the only folder (named jre1.8.0_281 or similar).
  3. Open the \bin folder.
  4. Open java.exe.

JAR Gives Security Error When Opening

Java has been seen as a security risk, so don’t be surprised if you get a warning when opening a JAR file.

To resolve this, open the Start menu, type configure java, and select the result. The Java Control Panel will open. Then:

  1. Click the Security tab.
  2. Ensure you have Enable Java content for browser and Web Start applications checked.
  3. Set the security level to High.
  4. Add to the exception site list if necessary.
  5. Click OK.

Java Isn’t Just for Windows

Hopefully, you now understand what a JAR file is, how to open it, and how to resolve any problems you might encounter.

While this guide has focussed on Windows, you can also get Java on other operating systems. That includes Ubuntu, where Java is useful whether you’re coding in the language or using an app.

Need to install Java on your Ubuntu system? Whether you’re coding in Java or using an app, here’s how to get it running.

Joe was born with a keyboard in his hands and immediately started writing about technology. He has a BA (Hons) in Business and is now a full-time freelance writer who enjoys making tech simple for everyone.

Subscribe To Our Newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

One More Step…!

Please confirm your email address in the email we just sent you.

Оцените статью