Swagger 2.0 Integration with Glassfish 4.1 OSGi REST Project

Do I need to specifically include JAX-RS and HttpServlet to integrate Swagger 2.0 into the JAX-RS project?

I am trying to introduce my RESTful services developed in the following specifications:

  • Java
  • NetBeans IDE 8.0.2 [Maven]
  • OSGi 4.2
  • The project exchanges information in JSON format
  • Glassfish 4.1
  • JAX-RS 2.0
  • Jersey 2.0

The project is successfully deployed to Glassfish, but when any of the REST services is called, it throws an error 404. The server log complains about class loading errors, in particular javax.ws.rs. * (despite javax.ws.rs -api) and produces java.lang.NoClassDefFoundError: javax/ws/rs/core/Application

pom.xml - Plugin 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>

Work done so far:

  • Updated Glassfish 4.1 to include Jersey 2 & JAX-RS 2
  • All Jersey-Glassfish dependencies designated as “provided”
+4
1

, javax.ws.rs. * . OSGi Module Management Subsystem Felix Gogo .

0

Source: https://habr.com/ru/post/1609035/


All Articles