Swagger-core: java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackag

Created on 20 Jul 2016  路  5Comments  路  Source: swagger-api/swagger-core

My code is like this
public class MyApplication extends Application {
public MyApplication() {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/api");
beanConfig.setResourcePackage("jerseyproject");
beanConfig.setScan(true);

}
@Override
public Set<Class<?>> getClasses() {
    final Set<Class<?>> classes = new HashSet<Class<?>>();
    // register root resource
    classes.add(MyResource.class);

    //you would need to add swagger-core's providers to the set up process.
    classes.add(io.swagger.jaxrs.listing.ApiListingResource.class);
    classes.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
    return classes;
}

}

but it throws error:

java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;
at io.swagger.jaxrs.config.BeanConfig.classes(BeanConfig.java:248)
at io.swagger.jaxrs.config.BeanConfig.scanAndRead(BeanConfig.java:221)
at io.swagger.jaxrs.config.BeanConfig.setScan(BeanConfig.java:204)
at jerseyproject.MyApplication.(MyApplication.java:23)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1350)
at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1009)
at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:961)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1053)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1045)
at org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:385)
at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:342)
at org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:392)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5337)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3858)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:291)
at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5660)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1376)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1380)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1380)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1348)
at java.lang.Thread.run(Unknown Source)

I am using swagger-core 1.5.9 version, what version of google reflection and google collections should I use to solve this error

Most helpful comment

I solved this by using a newest version of google reflection jar

All 5 comments

I solved this by using a newest version of google reflection jar

What version of reflection worked for you? i tried the latest didn't help.

Hi @kshitizbht, have you fixed a problem?
Used the different version of org.reflections (v0.9.11, 0.9.10) - does not help.

viachm, using swagger version 1.5.18 this aproach does not worked for me too, but I downgraded to swagger 1.5.9 and works.

@denisgmarques Finally, I downgraded org.reflections to 0.9.10 (excluding com.google.guava and com.google.code.findbugs) and it worked for me.

I guess in you'r case, while downgrading swagger to 1.5.9 - under the hood version of org.reflections was downgraded and that fixed you'r problem.

Was this page helpful?
0 / 5 - 0 ratings