Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a java library

Tags:

java

This may be a silly question, but right now I have a rather large class that I want to use as a library. Where somebody can simply add this jar file to their classpath. And then simply do an import statement at the top, then he or she can start using this class.

Is there anything special I need to do or can I simply just use the jar file built?

like image 685
Albinoswordfish Avatar asked Mar 15 '26 08:03

Albinoswordfish


1 Answers

a rather large class

Large classes don't usually make good libraries :)

Technically, yeah, all you need it put it in a JAR. To make it easy to use (including by yourself), you should spend some time to refactor it and break up the functionality into smaller classes according to the Single Responsibility Principle. For static utility methods, consider whether you can group them into several classes according to some theme, or perhaps even turn some of them into non-static methods (if there are situations where a client would use more than one of those methods on the same data, they're begging to become instance methods).

And you definitely should write Javadoc comments for all public classes and methods, and publish the Javadocs along with the code. A library without an API doc is almost useless.

like image 149
Michael Borgwardt Avatar answered Mar 16 '26 20:03

Michael Borgwardt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!