The Java Archive Tool (JAR) Examples
Learn how to use JAR tool: 1 – Create a jar file, 2 – Update a jar file , 3 – Extract a jar file , 4 – List files from a jar file, 5 – Add manifest into jar file
Favourite tutorials for developers
Learn how to use JAR tool: 1 – Create a jar file, 2 – Update a jar file , 3 – Extract a jar file , 4 – List files from a jar file, 5 – Add manifest into jar file
In Java, you can use manifest file to define application’s entry point, adding classpath or package version for a JAR file. In this short tutorial , we will show you how to add a custom manifest file into a Jar file.
This example shows you how to use Maven to exclude the log4j.properties file from your Jar file. Please, DO NOT include the log4j.properties into the final Jar file, it will cause multiple log4j.properties files in the classpath, if someone is depending on your Jar, you may accidentally override their logging configurations, depends which Jar is loaded first.
In this tutorial, we will show you how to create a executable JAR – When you double click on it, it runs the defined main class in manifest file.
For Java libraries that are not available in the Maven Central or other Maven repositories, we need to install it into our Maven Local repository in order to use it as a project dependencies. In this tutorial, we will show you how to install the kaptcha jar into our Maven local repository.
In Java, we can use the static or non-static ways to get the path of a running JAR file. We should use toURI() to avoid encoding the special characters in the file name.
In this tutorial, we will show you how to use Maven build tool, to create a single executable Jar, and how to deal with the project’s dependencies. Tools used :Maven 3.1.1 ; JDK 1.7 ; log4j 1.2.17 ; Joda-time 2.5 ; Eclipse 4.3 . We will demo how to use maven-dependency-plugin to copy all dependencies to target/dependency-jars/ folder, and use maven-jar-plugin to add the dependency classpath. Note: In future, if you want to move dateUtils.jar, make sure to copy its dependency-jars folder as well.
In Java, we can use getResourceAsStream or getResource to read a file or multiple files from a resources folder or root of the classpath. The getResourceAsStream method returns an InputStream. The getResource method returns an URL and normally convert it to a File; Not working in JAR file.