Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose: api.jar + impl.jar + bundle.jar?

Tags:

java

jar

I see many Java packages have api, impl and bundle jars (name-api.jar, name-impl.jar, name-bundle.jar). Could someone explain what those mean? Are all three needed by the app?

like image 532
Danijel Avatar asked Mar 22 '12 09:03

Danijel


People also ask

What is the difference between API and jar?

A rest API written in Java will return a JSON payload which can then be read and used by an application written in any programming language. This is the advantage of web services. A jar will return Java objects as a payload, so is optimal to use if you will be using it exclusively within other Java applications.

Why do we need a JAR file?

JAR files are packaged with the ZIP file format, so you can use them for tasks such as lossless data compression, archiving, decompression, and archive unpacking. These tasks are among the most common uses of JAR files, and you can realize many JAR file benefits using only these basic features.

What is a JAR file package?

A JAR ("Java archive") file is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution. Java Archive.


2 Answers

The idea is that you can separate the dependencies of the application; in an attempt to make applications more portable. The idea is that you can make the application dependent on the api.jar when compiling. Then when you want to run the program you can then switch in the appropriate implementation jar (impl.jar) and the appropriate resource bundle jar (bundle.jar).

As an example suppose the library does some database interaction. You write your code so that it references the api.jar. Now suppose you need it to work with a specific type of database e.g. MySQL - you would then add the impl.jar that is specific to MySQL databases to the classpath to get it to work (if you need a different database later - you only need to switch that jar in the classpath).

The bundle.jar is a bit more obscure and not as common. This could be used to supply configuration setting for the library. For example it could be used to supply language specific settings, or some more specific config. In the case of the database library it might be that the implementation is designed for all versions of MySQL, and the resource bundle jar provides config files that allow it to work for a specific MySQL version.

like image 133
Mark Rhodes Avatar answered Nov 09 '22 10:11

Mark Rhodes


Often :

  • name-api.jar contains only the interface of the API.
  • name-impl.jar provides an implementation of all interfaces in the name-api.jar
  • name-bundle.jar bundles everything with all the needed classes to run a Java application.
like image 45
Sandro Munda Avatar answered Nov 09 '22 10:11

Sandro Munda