JAX-RS in relation to Jersey and JSRs

前端 未结 2 1150
南笙
南笙 2020-12-16 16:33

I\'m trying to get my head around some concepts in Java:

  1. JSR(s): describe specifications, but carry no actual implementations. E.g. http://jsr311.java.net/ is
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 17:11

    1. One can download files from a variety of sources. To get the most official version of the JSR-311 specification go to its JCP download page. It's quite possible that you can't get a JAR file (with all the interfaces and stuff) from JCP pages, but still, this is the official source. (There are always nice PDFs of public drafts also!)
    2. You're right, because Jersey contains the API defined by JSR-311, however I would add a compile dependency to the jsr311-api JAR file and add Jersey as runtime dependency. This creates a nice separation between API and implementation and you can swap out your JSR-311 implementation anytime [sic]. If you intend to use Jersey all the way include only Jersey. One less dependency in your POM.
    3. If Jersey packages the same API as the jsr311-api JAR contains, it won't. If it packages something different, well, that would be awful! Maven will probably bark at compile time if one has a corrupt JSR-311 API on its classpath (I've already seen lots of java.lang.ClassFormatError: Absent Code attribute in method that ... errors, so it won't go unnoticed, that's for sure).

    Other than these, you're right.

提交回复
热议问题