Questions tagged [jar]
JAR file (or Java ARchive) aggregates many files into one. JAR files build on the ZIP file format.
18,963
questions
1401
votes
46
answers
2.5m
views
Can't execute jar- file: "no main manifest attribute"
I have installed an application and when I try to run it (it's an executable jar) nothing happens. When I run it from the command line with:
java -jar "app.jar"
I get the following message:...
671
votes
24
answers
916k
views
How to build JARs from IntelliJ IDEA 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 would like to have the ...
650
votes
33
answers
629k
views
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 ...
589
votes
16
answers
459k
views
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?
512
votes
24
answers
301k
views
"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" ...
450
votes
16
answers
653k
views
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 ...
385
votes
21
answers
398k
views
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 ...
378
votes
4
answers
157k
views
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 ...
360
votes
12
answers
958k
views
How to import a jar in Eclipse?
How do I import a jar in Eclipse?
358
votes
15
answers
502k
views
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(...
352
votes
8
answers
767k
views
How to decompile a whole Jar file? [closed]
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
333
votes
7
answers
376k
views
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 ...
319
votes
4
answers
976k
views
Run jar file in command prompt [duplicate]
How do we run a jar file in command prompt?
305
votes
35
answers
288k
views
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.)
305
votes
25
answers
1.6m
views
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 ...
300
votes
31
answers
523k
views
Viewing contents of a .jar file [closed]
What would be the easiest way to view classes, methods, properties, etc. inside a jar file?
I'm looking for something equivalent to the very useful Lutz Roeder .NET Reflector - for Java
276
votes
12
answers
893k
views
How to run a JAR file
I created a JAR file like this:
jar cf Predit.jar *.*
I ran this JAR file by double clicking on it (it didn't work). So I ran it from the DOS prompt like this:
java -jar Predit.jar
It raised "...
274
votes
22
answers
266k
views
What version of javac built my jar?
How can I tell what version of the Java compiler was used to build a jar? I have a jar file, and it could have been built in any one of three JDKs. We need to know exactly which one, so we can ...
268
votes
21
answers
389k
views
What causes java.lang.IncompatibleClassChangeError?
I'm packaging a Java library as a JAR, and it's throwing many java.lang.IncompatibleClassChangeErrors when I try to invoke methods from it. These errors seem to appear at random. What kinds of ...
254
votes
16
answers
414k
views
How to add a jar in External Libraries in Android Studio?
I am new to Android Studio.
How can I add a few jar files in the External Libraries below the < JDK > folder?
236
votes
10
answers
449k
views
Controlling Maven final name of jar artifact
I'm trying to define a property in our super pom which will be used by all child projects as the destination of the generated artifact.
For this I was thinking about using project/build/finalName yet ...
236
votes
6
answers
429k
views
How to run a class from Jar which is not the Main-Class in its Manifest file
I have a JAR with 4 classes, each one has Main method. I want to be able to run each one of those as per the need. I am trying to run it from command-line on Linux box.
E.g. The name of my JAR is ...
232
votes
10
answers
652k
views
java.lang.NoClassDefFoundError: Could not initialize class XXX
public class PropHolder {
public static Properties prop;
static {
//code for loading properties from file
}
}
// Referencing the class somewhere else:
Properties prop = PropHolder.prop;
...
218
votes
7
answers
221k
views
Add JAR files to a Spark job - spark-submit
True... it has been discussed quite a lot.
However, there is a lot of ambiguity and some of the answers provided ... including duplicating JAR references in the jars/executor/driver configuration or ...
217
votes
10
answers
200k
views
Create aar file in Android Studio
I'd like to create an aar file for my library in Android Studio, i would've gone with a jar option but my library has resources.
Any idea how to create an aar file from a library?
213
votes
11
answers
637k
views
Extract source code from .jar file
Is there a way to extract the source code from an executable .jar file (Java ME)?
211
votes
5
answers
386k
views
Run class in Jar file
If you have a jar file called myJar.jar located in /myfolder and you want to use the class called myClass from it, how do you go about doing it from the command line?
I thought it would be to go into ...
209
votes
43
answers
1.2m
views
What causes "Unable to access jarfile" error?
I want to execute my program without using an IDE.
I've created a jar file and an exectuable jar file. When
I double click the exe jar file, nothing happens, and when I try to use the command in cmd ...
208
votes
22
answers
340k
views
Access restriction: The type 'Application' is not API (restriction on required library rt.jar)
Here is the code:
package mscontroller;
import javax.swing.*;
import com.apple.eawt.Application;
public class Main {
public static void main(String[] args)
{
Application app = new ...
201
votes
12
answers
340k
views
Creating runnable JAR with Gradle
Until now I created runnable JAR files via the Eclipse "Export..." functionallity but now I switched to IntelliJ IDEA and Gradle for build automation.
Some articles here suggest the "application" ...
197
votes
6
answers
133k
views
What is a fat JAR? [duplicate]
I've heard people say that they create a fat JAR and deploy it. What do they actually mean ?
189
votes
5
answers
115k
views
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 ...
188
votes
9
answers
114k
views
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 ...
181
votes
15
answers
321k
views
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:...
173
votes
7
answers
228k
views
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 ...
168
votes
6
answers
103k
views
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 ...
168
votes
12
answers
422k
views
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?
166
votes
46
answers
566k
views
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 ...
166
votes
13
answers
176k
views
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: . ...
160
votes
11
answers
89k
views
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 ...
158
votes
8
answers
190k
views
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, ...
158
votes
5
answers
407k
views
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. (...
155
votes
13
answers
209k
views
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.
155
votes
5
answers
82k
views
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 ...
154
votes
6
answers
194k
views
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 ...
153
votes
17
answers
180k
views
How to list the files inside a JAR file?
I have this code which reads all the files from a directory.
File textFolder = new File("text_directory");
File [] texFiles = textFolder.listFiles( new FileFilter() {
public ...
152
votes
5
answers
307k
views
How to use classes from .jar files?
I read the Java tutorials on Sun for JAR files, but I still can't find a solution for my problem. I need to use a class from a jar file called jtwitter.jar, I downloaded the file, and tried executing ...
146
votes
5
answers
178k
views
Gradle - no main manifest attribute
I'm building a JAR file with Gradle. When I try to run it I get the following error
no main manifest attribute, in RxJavaDemo.jar
I tried manipulating the manifest property but I think I'm ...
140
votes
8
answers
148k
views
Execute another jar in a Java program
I had written several simple java applications named as A.jar, B.jar.
Now i want to write a GUI java program so that user can press button A to execute A.jar and button B to execute B.jar.
Also i ...
137
votes
5
answers
102k
views
Java, Classpath, Classloading => Multiple Versions of the same jar/project
I know this may be a silly question for experienced coders. But I have a library (an http client) that some of the other frameworks/jars used in my project require. But all of them require different ...