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

前端 未结 4 1604
情歌与酒
情歌与酒 2021-01-12 02:47

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 ap

相关标签:
4条回答
  • 2021-01-12 03:21

    I've never seen such an arrangement.

    If the designer packaged the app into three JARs, then I'd say all three are needed.

    But you should recognize that it's just a choice made by the designer. It's possible that s/he could have just created a single JAR with everything in it and you'd be none the wiser.

    I'm guessing now, but if you were to open those JARs you'd see only interfaces in the API JAR, implementations of those interfaces in the impl JAR, and resource bundles and other .properties files in the bundle JAR. Try it and see. You'll learn something.

    0 讨论(0)
  • 2021-01-12 03:31

    api.jar contains API interfaces. These are interfaces as a contract that the implementation of the API should follow.

    impl.jar is the implementation of the api.jar. You can't just have the impl.jar without the api.jar.

    bundle.jar is the resources (if I'm not mistaken). Those are resources needed for the implementation code necessary to run.

    0 讨论(0)
  • 2021-01-12 03:36

    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.
    0 讨论(0)
  • 2021-01-12 03:46

    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.

    0 讨论(0)
提交回复
热议问题