4

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

I am trying to present 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 deploys successfully onto Glassfish, but when any of the REST services are called, it throws an Error 404. The server log complains about class loading errors, specifically javax.ws.rs.* (despite javax.ws.rs-api being provided), and produces java.lang.NoClassDefFoundError: javax/ws/rs/core/Application

pom.xml -- Maven Bundle Plugin

<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 marked as "provided"
  • Resolved duplicate dependencies
danskianz
  • 43
  • 5

1 Answers1

0

Make sure that the javax.ws.rs.* packages are provided by the system bundle. You can connect to the OSGi Module Management Subsystem of glassfish using the Felix Gogo Remote Shell and query the registry using the built-in commands.

pharsfalvi
  • 787
  • 1
  • 8
  • 12