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:

18886 questions
187
votes
6 answers

What is a fat JAR?

I've heard people say that they create a fat JAR and deploy it. What do they actually mean ?
erwaman
  • 3,307
  • 3
  • 28
  • 29
186
votes
9 answers

How to build sources JAR with Gradle?

I am working with an open source project that is built with Gradle. I would like to generate a (project)-sources.jar file that I can load into my IDE (IntelliJ IDEA) and debug through the project. I know how to load the file if I can generate it. I…
Paul D. Eden
  • 19,939
  • 18
  • 59
  • 63
185
votes
5 answers

Determine which JAR file a class is from

I am not in front of an IDE right now, just looking at the API specs. CodeSource src = MyClass.class.getProtectionDomain().getCodeSource(); if (src != null) { URL jar = src.getLocation(); } I want to determine which JAR file a class is from. Is…
Walter White
180
votes
15 answers

Deploying Maven project throws java.util.zip.ZipException: invalid LOC header (bad signature)

I am getting the below exception when I run my mvn install. I have even deleted the local repository and ran again getting same exception. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default) on project…
Karthick
  • 1,943
  • 3
  • 15
  • 16
173
votes
7 answers

Build project into a JAR automatically in Eclipse

I have an Eclipse project where I want to keep my Java project built into a JAR automatically. I know I have an option to export the project into a JAR; if I do a right click; but what I am really looking for is, that like Eclipse automatically…
Priyank
  • 14,231
  • 18
  • 78
  • 107
163
votes
13 answers

File inside jar is not visible for spring

All I created a jar file with the following MANIFEST.MF inside: Manifest-Version: 1.0 Ant-Version: Apache Ant 1.8.3 Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.) Main-Class: my.Main Class-Path: . lib/spring-core-3.2.0.M2.jar…
BTakacs
  • 2,397
  • 3
  • 24
  • 26
162
votes
47 answers

Eclipse error: "The import XXX cannot be resolved"

I'm trying to work with Hibernate in Eclipse. I'm creating a new simple project and I've downloaded a collegue project too, via CVS. Both don't work, while on my collegue's Eclipse do. The problem is that, for each import of an Hibernate class,…
bluish
  • 26,356
  • 27
  • 122
  • 180
161
votes
12 answers

How to include jar files with java file and compile in command prompt

I have 3 jar files and a .java file that depends on these jar files. How do I compile the .java file with these jar files using a command prompt?
user1177567
  • 1,663
  • 2
  • 12
  • 9
161
votes
6 answers

Is it possible to rename a maven jar-with-dependencies?

I'm currently using the jar-with-dependencies assembly to create such a jar. However, the name of my jar is a bit long. Since this jar is being used by RPG programs on an AS400, I'd like to shorten it to make life a bit easier for those…
Mike Cornell
  • 5,909
  • 4
  • 29
  • 38
160
votes
11 answers

Create an Android Jar library for distribution

I know of Android Library projects, which allow you to create a shared-source project that can be pulled into Android Applications as needed. However, that requires that source be available. I'm looking for a way to build and distribute a…
psychotik
  • 38,153
  • 34
  • 100
  • 135
154
votes
5 answers

Android Archive Library (aar) vs standard jar

I've been reading some articles about the new adoption of Gradle as the standard build system for Android apps. Well, coming from standard Java development I usually depend on jar files in order to build my project. However it seems that Android has…
Aritz
  • 30,971
  • 16
  • 136
  • 217
154
votes
7 answers

Building a fat jar using maven

I have a code base which I want to distribute as jar. It also have dependency on external jars, which I want to bundle in the final jar. I heard that this can be done using maven-assembly-plug-in, but I don't understand how. Could someone point me…
bianca
  • 7,004
  • 12
  • 43
  • 58
153
votes
6 answers

Differences between "java -cp" and "java -jar"?

What is the difference between running a Java application withjava -cp CLASSPATH and java -jar JAR_FILE_PATH? Is one of them preferred to the other for running a Java application? I mean which one of these ways is more expensive for JVM (according…
Reza
  • 2,058
  • 3
  • 20
  • 33
151
votes
5 answers

Including jars in classpath on commandline (javac or apt)

trying to run this program. I think that to setup all of the web service stuff I need to run apt. (Although using javac I am having the same issue). I think what I am getting is compile errors. (Shown at bottom). I think what I need to do is…
sixtyfootersdude
  • 25,859
  • 43
  • 145
  • 213
150
votes
13 answers

How to get names of classes inside a jar file?

I have a JAR file and I need to get the name of all classes inside this JAR file. How can I do that? I googled it and saw something about JarFile or Java ClassLoader but I have no idea how to do it.
sticksu
  • 3,660
  • 3
  • 23
  • 41