Friday, June 20, 2025
HomeJava4 Greatest practices to call your JAR file in Java

4 Greatest practices to call your JAR file in Java


In case you are an creator of an inner, proprietary Java library or an exterior open-source library,  or you’re a kind of fortunate builders who ship Java purposes by your self then it’s best to observe these finest practices whereas naming your JAR recordsdata. These finest practices are a results of the sensible expertise of utilizing tons of of Java libraries and purposes. Following these finest practices will assist in higher administration of JAR recordsdata. It is a part of my different finest practices articles like finest practices whereas naming a variable, writing feedback, overriding strategies, multi-threading, JDBC, and finest practices whereas coping with passwords. In case you are considering studying extra about finest practices, it’s best to learn these articles.
You too can check out Efficient Java, the mom of all finest practices within the Java world, and one of many must-read books for any Java developer. Joshua Bloch, creator of this e book has additionally authored a number of key lessons in JDK like Java Assortment Framework and different necessary lessons in java.lang, and java.util packages.

4 Greatest Practices for Naming JAR Information in Java 

Now let’s have a look at some finest practices whereas naming your JAR file:

1) Give them a particular title, want concrete over summary
For instance, util.jar is the worst jar file title I can consider. All I do know is it accommodates some utility/helper lessons. However it’s unclear in the event that they belong to an utility server, or a framework, or any utility sub-systems. You have to to ask somebody or confer with docs to know what it’s. It is a part of the DataDirect JDBC Driver distribution. However, good jar file names are all the time self-explanatory, for instance, struts.jar or spring-mvc.jar

2. Use hyphen (-) as an alternative of underscore (_) as a phrase separator
There are two causes I counsel you to want hyphen(-) over underscore(_). First, it is simpler to sort hyphen than underscore; secondly, when the file title is underlined (like in a hyperlink), the _ is invisible. Hyphen has been shunned in file names partly as a result of it’s an unlawful character in java identifier. However this concern is unwarranted. One of many examples of this finest apply is spring-mvc.jar which makes use of a hyphen to hitch two phrases.

3. Append model quantity if distributed standalone
In case your JAR file is distributed standalone then you will need to append the model quantity on the title of the JAR file as a result of they are often dropped into any purposes, which can want particular variations. We do not need customers to have to check file measurement or extract some META-INF recordsdata to know its model. Some examples of this finest apply are hibernate3.jar, commons-logging-1.0.3.jar, and log4j-1.2.8.jar.

4. At all times use extension “.jar”, not “.zip”
Theoretically, jar recordsdata can have any extension or no extension in any respect. In the event you specify it within the system classpath, it ought to be loadable. The issue is with computerized library detection and loading by containers and frameworks. It is costly to scan all recordsdata so some form of extension restriction is required. For that reason, J2EE/JavaEE platform spec requires all library jar recordsdata to make use of “.jar” extension, resembling WEB-INF/lib/mybeans.jar.

Here’s a abstract of the above 4 finest practices Java builders ought to observe whereas naming their JAR recordsdata:

That is all on finest practices to call your JAR file in Java. Let me know what are your ideas about these practices, do you already observe them? Do they make sense? In case you are following some other finest practices then tell us as effectively.

Additional Studying

  1. Greatest Practices to call your variable, class, and strategies (see right here)
  2. Greatest Practices to observe whereas overriding strategies in Java (see right here)
  3. Prime 10 Multithreading and Concurrency Greatest Practices in Java (see right here)
  4. Prime 10 JDBC Greatest Practices for Java Programmer (see right here)
  5. Greatest Practices whereas coping with passwords in Java (see right here)
  6. 10 Greatest Practices to observe whereas writing code feedback (see right here)
  7. 10 Exception dealing with Greatest Practices in Java (see right here)
  8. Greatest Practices whereas writing JUnit checks in Java (see right here)
  9. Greatest Practices to Keep away from NullPointerException in Java (see right here)
  10. Efficient Java – Mom of All Greatest Practices in Java (see right here)

Thanks for studying this text thus far. In the event you discover these Java finest practices for naming JAR recordsdata then please share them with your folks and colleagues. When you have questions please ask. 



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments