将 Swagger 2.0 与 Glassfish 4.1 OSGi REST 项目集成

Integrating Swagger 2.0 with Glassfish 4.1 OSGi REST project

我是否需要特别包含 JAX-RS 和 HttpServlet jar 以将 Swagger 2.0 集成到我的 JAX-RS 项目中?

我正在尝试展示我的 RESTful 按照以下规范开发的服务:

该项目已成功部署到 Glassfish 上,但是当调用任何 REST 服务时,它会抛出错误 404。服务器日志抱怨 class 加载错误,特别是 javax.ws.rs。*(尽管提供了 javax.ws.rs-api),并产生 java.lang.NoClassDefFoundError: javax/ws/rs/core/Application

pom.xml -- Maven Bundle 插件

<plugin>
              <groupId>org.apache.felix</groupId>
              <artifactId>maven-bundle-plugin</artifactId>
              <version>2.5.4</version>
              <extensions>true</extensions>
              <configuration>
                  <supportedProjectTypes>
                      <supportedProjectType>ejb</supportedProjectType>
                      <supportedProjectType>war</supportedProjectType>
                      <supportedProjectType>bundle</supportedProjectType>
                      <supportedProjectType>jar</supportedProjectType>
                  </supportedProjectTypes>
                  <instructions>
                      <!-- Specify elements to add to MANIFEST.MF -->
                         <Web-ContextPath>/sample</Web-ContextPath>
                      <!-- By default, nothing is exported -->
                         <!--<Export-Package>!*.impl.*, *</Export-Package>-->
                         <Import-Package>
                             !com.sun*;resolution:=optional,
                             !javassist*;resolution:=optional,
                             !groovy*;resolution:=optional,
                             !javax.microedition*;resolution:=optional,
                             !org.apache*;resolution:=optional,
                             !org.codehaus*;resolution:=optional,
                             !nu.xom;resolution:=optional,
                             !org*;resolution:=optional,*
                         </Import-Package>
                         <Bundle-ClassPath>.,WEB-INF/classes,WEB-INF/lib/slf4j-api-1.7.12.jar,WEB-INF/lib/slf4j-jdk14-1.7.12.jar,{maven-dependencies}</Bundle-ClassPath>
                         <Embed-Dependency>
                             annotations,asm-all-repackaged,cglib,
                             aopalliance-repackaged,commons-lang3,commons-vfs2,
                             dom4j,gson,guava,
                             hk2-api,hk2-locator,hk2-utils,
                             jackson-core,jackson-annotations,jackson-databind,
                             jackson-dataformat-yaml,jackson-dataformat-xml,
                             jackson-datatype-joda,jackson-jaxrs-base,
                             jackson-jaxrs-json-provider,
                             jackson-module-jaxb-annotations,
                             javaee-web-api,
                             javassist,
                             javax.ws.rs-api,
                             javax.annotation-api,javax.inject,javax.json-api,
                             javax.servlet-api,
                             jaxen,jaxb-api,
                             jersey-client,jersey-common,jersey-server,
                             jersey-container-servlet-core,
                             jersey-media-multipart,
                             joda-convert,joda-time,jsch,jsr311-api,jzlib,
                             logback-classic,logback-core,
                             mongo-java-driver,maven,mimepull,
                             org.apache.felix.scr.annotations,
                             org.apache.servicemix.bundles.commons-httpclient,
                             org.osgi.compendium,org.osgi.core,
                             osgi-cdi-api,osgi-resource-locator,
                             pull-parser,reflections,
                             slf4j-api,slf4j-jdk14,
                             snakeyaml,stax2-api,
                             swagger-annotations,swagger-core,swagger-jaxrs,
                             swagger-jersey2-jaxrs,swagger-models,
                             validation-api;
                             scope=compile|runtime;
                         </Embed-Dependency>
                         <Embed-Transitive>true</Embed-Transitive>
                  </instructions>
              </configuration>
              <executions>
                  <execution>
                      <id>bundle-manifest</id>
                      <phase>process-classes</phase>
                      <goals>
                          <goal>manifest</goal>
                      </goals>
                  </execution>
                  <execution>
                      <id>bundle-install</id>
                      <phase>install</phase>
                      <goals>
                          <goal>install</goal>
                      </goals>
                  </execution>
              </executions>
            </plugin>

到目前为止完成的工作:

确保 javax.ws.rs.* 包由系统包提供。您可以使用 Felix Gogo Remote Shell 连接到 glassfish OSGi Module Management Subsystem 并使用内置命令查询注册表。