Swagger jersey API not working with embedded grizzly

195 views
Skip to first unread message

shipra...@gmail.com

unread,
Sep 11, 2018, 5:38:55 AM9/11/18
to Swagger

project.PNG

I have a jersey project in this structure, which consist of swagger annotations . I have used it with standalone tomcat server and the API is running fine. Now I am trying to run the same API with an embedded Grizzly server. I have written the main function for that as follows:



import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;

import java.io.IOException;
import java.net.URI;

/**
* Main class.
*
*/
public class Main {
// Base URI the Grizzly HTTP server will listen on
public static final String BASE_URI = "http://localhost:8087";

/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
* @return Grizzly HTTP server.
*/
public static HttpServer startServer() {
// create a resource config that scans for JAX-RS resources and providers
// in de.fraunhofer.fit.mas package
final ResourceConfig rc = new ResourceConfig().packages("de.fraunhofer.fit.mas","io.swagger.jaxrs.listing");

// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}

/**
* Main method.
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.stop();
}
}


Unfortunately, my servlet configure file is not being found. I get a error of this kind :

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletConfig
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructors(Class.java:1651)
at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.<init>(MethodHandler.java:265)
at org.glassfish.jersey.server.model.MethodHandler.create(MethodHandler.java:155)
at org.glassfish.jersey.server.model.ResourceMethod$Builder.createInvocable(ResourceMethod.java:559)
at org.glassfish.jersey.server.model.ResourceMethod$Builder.build(ResourceMethod.java:545)
at org.glassfish.jersey.server.model.Resource$Builder.processMethodBuilders(Resource.java:666)
at org.glassfish.jersey.server.model.Resource$Builder.buildResourceData(Resource.java:602)
at org.glassfish.jersey.server.model.Resource$Builder.build(Resource.java:658)
at org.glassfish.jersey.server.model.Resource.from(Resource.java:801)
at org.glassfish.jersey.server.ResourceBagConfigurator.init(ResourceBagConfigurator.java:79)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:354)
at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:316)
at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:256)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:315)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:282)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:269)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:334)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:117)
at Main.startServer(Main.java:27)
at Main.main(Main.java:36)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletConfig
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)


Can someone help me in this regard? 


Reply all
Reply to author
Forward
0 new messages