Questions tagged [jar]

JAR file (or Java ARchive) aggregates many files into one. JAR files build on the ZIP file format.

A file allows runtimes to efficiently deploy a set of classes and their associated resources. The elements in a JAR file can be compressed, which, together with the ability to download an entire application in a single request, makes downloading a JAR file much faster than separately downloading the many uncompressed files which would form a single Java Application. External libraries for Java language are very often represented as JAR files too. The package java.util.jar contains classes that read and write JAR files.

JAR file usually contains a manifest file - /META-INF/MANIFEST.MF. Manifest can contain additional meta information about the packaged code, such as version note, package vendor, packaging utility (e.g. ant or maven) used to build the package, implemented specification reference and so on. For executable JAR file manifest is mandatory.

JAR files can also be signed with a certificate to prevent unathorized modification. For Java applets and Java Web Start applications a proper JAR signature is quite important, as modern browsers won't trust unsigned or self-signed Java applications. Oracle jarsigner tool can be used for both JAR signing and signature verification.

Proper MIME type for JAR file is "application/java-archive".

To run your JAR file use: java -jar YourApp.jar

Frequently Asked Questions

People often ask these questions about this topic:

17891 questions
1124
votes
42 answers

Can't execute jar- file: "no main manifest attribute"

I have installed an application, when I try to run it (it's an executable jar) nothing happens. When I run it from the commandline with: java -jar "app.jar" I get the following message: no main manifest attribute, in "app.jar" Normally, if I…
Ewoud
  • 11,439
  • 4
  • 15
  • 22
602
votes
32 answers

How to get the path of a running JAR file?

My code runs inside a JAR file, say foo.jar, and I need to know, in the code, in which folder the running foo.jar is. So, if foo.jar is in C:\FOO\, I want to get that path no matter what my current working directory is.
Thiago Chaves
  • 8,439
  • 5
  • 25
  • 25
588
votes
22 answers

How to build jars from IntelliJ properly?

I have a project that contains a single module, and some dependencies. I'd like to create a jar, in a separate directory, that contains the compiled module. In addition, I'd like to have the dependencies present beside my module. No matter how I…
ripper234
  • 202,011
  • 255
  • 600
  • 878
497
votes
14 answers

Difference between jar and war in Java

What is the difference between a .jar and a .war file? Is it only the file extension or is there something more?
helpermethod
  • 51,037
  • 60
  • 165
  • 263
475
votes
22 answers

"Invalid signature file" when attempting to run a .jar

My java program is packaged in a jar file and makes use of an external jar library, bouncy castle. My code compiles fine, but running the jar leads to the following error: Exception in thread "main" java.lang.SecurityException: Invalid signature…
user123003
388
votes
15 answers

Including dependencies in a jar with Maven

Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file? I have a project the builds into a single jar file. I want the classes from dependencies to be copied into the jar as well. Update: I know that I cant just…
racer
  • 3,967
  • 3
  • 16
  • 13
342
votes
10 answers

How to import a jar in Eclipse

How do I import a jar in Eclipse?
user395734
  • 3,431
  • 2
  • 13
  • 4
332
votes
20 answers

How to load JAR files dynamically at Runtime?

Why is it so hard to do this in Java? If you want to have any kind of module system you need to be able to load JAR files dynamically. I'm told there's a way of doing it by writing your own ClassLoader, but that's a lot of work for something that…
Allain Lalonde
  • 85,857
  • 67
  • 175
  • 234
311
votes
4 answers

What is the maven-shade-plugin used for, and why would you want to relocate Java packages?

I found the maven-shade-plugin being used in someone's pom.xml. I've never used maven-shade-plugin before (and I'm a Maven n00b) so I tried to understand the reason for using this and what it does. I looked at the Maven docs, however I can't…
nonbeing
  • 5,809
  • 6
  • 28
  • 41
302
votes
8 answers

How to decompile a whole Jar file?

Does anyone know of a free decompiler that can decompile an entire Jar file instead of a single class? I have a problem with sub classes like name$1.class name$2.class name.class
StoneHeart
  • 14,122
  • 31
  • 65
  • 83
295
votes
4 answers

Run jar file in command prompt

How do we run a jar file in command prompt?
Nirav
  • 5,450
  • 4
  • 32
  • 44
289
votes
15 answers

Reading a resource file from within jar

I would like to read a resource from within my jar like so: File file; file = new File(getClass().getResource("/file.txt").toURI()); BufferedReader reader = new BufferedReader(new FileReader(file)); //Read the file and it works fine when running…
Koi
  • 2,993
  • 2
  • 10
  • 5
280
votes
7 answers

Difference between maven scope compile and provided for JAR packaging

What is the difference between the maven scope compile and provided when artifact is built as a JAR? If it was WAR, I'd understand - the artifact would be included or not in WEB-INF/lib. But in case of a JAR it doesn't matter - dependencies aren't…
emstol
  • 5,061
  • 5
  • 23
  • 32
265
votes
35 answers

Find a class somewhere inside dozens of JAR files?

How would you find a particular class name inside lots of jar files? (Looking for the actual class name, not the classes that reference it.)
Kapsh
  • 17,761
  • 11
  • 33
  • 42
257
votes
26 answers

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: java -jar helloworld.jar This works fine, but how do I execute it with double-click instead? Do I need to install any…
DonX
  • 15,033
  • 20
  • 71
  • 119
1
2 3
99 100