How to create your own java library (API)?

I created a Java program, and I designed it so that the methods that I want them to be displayed (getter methods) basically, I can easily call them after starting a class containing these methods.

The question is, do I need to make this application (which contains getter methods) look like an API so that I can give my application developers the opportunity to use my functions (getter methods) if they need them, and only what they need is add this file (I think the API after that is shown as a .jar file).

How can I do this so that I can make my code reusable with another application? I think it looks like a dll.

Thank you so much;)

+44
java
Aug 31 '10 at 19:39
source share
7 answers

Create a JAR. Then enable the JAR. Any classes in this JAR will be available. Just make sure you protect your code if you issue an API. Do not provide end users with any methods / properties that should not be used.

Edit: In response to your comment, make sure you did not include the source when packing the JAR. Include only class files. This is the best you can really do.

+42
Aug 31 '10 at 19:42
source share
โ€” -

To be used as an API, your classes must:

  • Use a unique package (ideally following the agreement, i.e. the back of the domain that you own as a prefix). This prevents name conflicts.
  • Use only public or protected classes and methods that are intended for use by others. This simplifies use.
  • Get extensive Javadoc comments.
  • Be available as a JAR file - ideally separate JAR files for binary distribution, source code and javadoc files.
+15
Aug 31 '10 at 19:49
source share

You need to pack the application as a jar file. You can use the ant jar task to create jar files, or you can use the jar command.

In ant tasks, see the link.

To create it manually, look at the link.

+10
Aug 31 '10 at 19:43
source share

Make sure you write and publish javadocs for all your public and protected classes and methods.

+6
Aug 31 '10 at 19:44
source share

To create a jar:

 jar cf <jar_name> <sources> 
+5
Jul 31 '12 at 22:35
source share

There are several ways to set your code. Creating an ATM and distributing it, which might be the easiest, as other developers just have to turn on your bank. However, if you are talking about โ€œanyโ€ access to your code, a web service may make more sense, since you can provide access to data without providing all the necessary code. You indicate that you provide access to your getters - if you just create a class with getters, other developers can use them, but how will they be populated? If your application is self-sufficient, it receives the necessary data and provides getters that should work, but if you are talking about providing access to data from your running application, the web service makes more sense, since your application can retrieve data and provide access using publicly available methods.

Most likely, you want to create interfaces so that developers can code the interface, and you can change the internal work without affecting them. Any API that will be used by others should also be documented.

+4
Aug 31 '10 at 19:51
source share

Well, depends on your IDE. I use Netbeans, so I just hit the build project and alt! The jar file is created in the specified directory. Now it is easy to compile. All you have to do is upload your .jar file, and if in Netbeans, right-click the library, add jar / folder and select the downloaded file.

+1
Aug 21 '15 at 22:05
source share



All Articles