How to run a JAR file

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: Test.java: public class Test { public static void main(String[] args) { System.out.println(“Hello world”); } } manifest.mf: Manifest-version: 1.0 Main-Class: Test Note that the text file must end with … Read more

Running JAR file on Windows

Easiest route is probably upgrading or re-installing the Java Runtime Environment (JRE). Or this: 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… … Read more

How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib

The CLASSPATH environment variable is only used by the java.exe command and even then only when the command is invoked without any of the -cp, -classpath, -jar arguments. The CLASSPATH environment variable is ignored by IDEs like Eclipse, Netbeans and IDEA. See also java.lang.ClassNotFoundException in spite of using CLASSPATH environment variable. The Build Path is … Read more

How to build jars from IntelliJ properly?

Here’s how to build a jar with IntelliJ 10 http://blogs.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/ File -> Project Structure -> Project Settings -> Artifacts -> Click green plus sign -> Jar -> From modules with dependencies… The above sets the “skeleton” to where the jar will be saved to. To actually build and save it do the following: Extract to … Read more

Building a fat jar using maven

Note: If you are a spring-boot application, read the end of answer Add following plugin to your pom.xml The latest version can be found at … <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>CHOOSE LATEST VERSION HERE</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>assemble-all</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> … After configuring … Read more

What causes java.lang.IncompatibleClassChangeError?

This means that you have made some incompatible binary changes to the library without recompiling the client code. Java Language Specification ยง13 details all such changes, most prominently, changing non-static non-private fields/methods to be static or vice versa. Recompile the client code against the new library, and you should be good to go. UPDATE: If … Read more

How to make an executable JAR file?

A jar file is simply a file containing a collection of java files. To make a jar file executable, you need to specify where the main Class is in the jar file. Example code would be as follows. public class JarExample { public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { … Read more