Java Tips & Tricks vol.2

Java Tips & Tricks vol.2

June 4, 2014

Paths and JARs

These are just some tips and tricks I used or read last month that I’d like to share. This list does not contain silver bullets and it doesn’t pretend to be complete or be an absolute truth. It’s just a list that I hope may be helpful for someone. Here is the begging of the post: Java tips & tricks| Paths and JARs. So, let’s continue:

4. Read a JAR file

As we know JAR files are zip files so to read a jar file is really easy:

ZipFile file = null;
		try {
			file = new ZipFile("filename.jar");
		} catch (IOException e) {
		if (file != null) {
			Enumeration<? extends ZipEntry> entries = file.entries();
			if (entries != null) {
				while (entries.hasMoreElements()) {
					ZipEntry entry = entries.nextElement();
					// Write your logic here.

Also, we can create JAR file programmatically but this won’t be discussed in this post. For more information you can check this link:

5. Difference between WAR, EAR and JAR files

These files are simply zipped files using java jar tool. These files are created for different purposes. Here is the description of these files:

  • .jar files: These files are with the .jar extension. The .jar files contain the libraries, resources and accessories files like property files.
  • .war files: These files are with the .war extension. The war file contains the web application that can be deployed on the any servlet/jsp container. The .war file contains jsp, html, javascript and other files for necessary for the development of web applications.
  • .ear files: The .ear file contains the EJB modules of the applications.

6.More about JARs

Finally, if you like this post and you are interesting about JAR files you can look at these links:

Share your thoughts with us in the comment section. What tricks do you use?

Boris Velichkov

Java EE and Oracle Developer

More Posts - Website

Follow Me:

Do you want more great blogs like this?

Subscribe for Dreamix Blog now!