tags:

views:

97

answers:

4

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?

+2  A: 

You can simply put the JAR into the classpath and can import the class. No more magic needed.

Mnementh
+1  A: 

You should just be able to use the jar, as is. All you need to ensure is that the class files in the JAR are in the correct directory structure (according to their package names)

Class Foo in package bar -> bar/Foo.class in the jar

nahojkap
+1  A: 

create a JAR of .class files of your "large class" and then put that JAR in your CLASSPATH. Then you should be able to import the classes in the JAR via "import" statements. If you anticipate too many huge classes/libraries, check out the JVM parameters -Xms and -Xmx that takes care of heap usage.

ring bearer
+5  A: 

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.

Michael Borgwardt
Just what I was thinking ... although it sounds like these are static utility methods in which case I guess it's ok to put them all in one class providing they're related of course.
Adamski