kongchen / swagger-maven-plugin

JAX-RS & SpringMVC supported maven build plugin, helps you generate Swagger JSON and API document in build phase.
http://kongchen.github.io/swagger-maven-plugin/
Apache License 2.0
761 stars 450 forks source link

mvn install gives ClassNotFoundException: com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader #338

Open javaworkinggirl opened 8 years ago

javaworkinggirl commented 8 years ago

except from my pom.xml: `

com.github.kongchen
        <artifactId>swagger-maven-plugin</artifactId>
        <version>3.1.3</version>
        <configuration>
           <apiSources>
              <apiSource>
                 <springmvc>false</springmvc>
                 <locations>
                    com.twc.ctg.xxx.service.rest
                 </locations>
                 <schemes>
                    http
                 </schemes>
                 <host>0.0.0.0:8080</host>
                 <basePath>/api</basePath>
                 <info>
                    <title>xxx REST Apis</title>
                    <version>v1</version>
                    <!-- use markdown here because I'm using markdown for output,
                    if you need to use html or other markup language, you need to use your target language,
                     and note escape your description for xml -->
                    <description>
                       ECP REST Apis
                    </description>
                    <termsOfService>
                       http://mystropedia.corp.xxx.com/display/xxx/xxx+Project+Wiki
                    </termsOfService>
                    <contact>
                       <email>xxx.xxx@xxx.com</email>
                       <name>x</name>
                       <url>http://mystropedia.corp.xxx.com/display/xxx/xxx+Project+Wiki</url>
                    </contact>
                   <!-- <license>
                       <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
                       <name>Apache 2.0</name>
                    </license>-->
                 </info>
                <!-- <securityDefinitions>
                    <securityDefinition>
                       <name>basicAuth</name>
                       <type>basic</type>
                    </securityDefinition>
                    <securityDefinition>
                       <json>/securityDefinition.json</json>
                    </securityDefinition>
                 </securityDefinitions>-->
                 <!-- Support classpath or file absolute path here.
                 1) classpath e.g: "classpath:/markdown.hbs", "classpath:/templates/hello.html"
                 2) file e.g: "${basedir}/src/main/resources/markdown.hbs",
                     "${basedir}/src/main/resources/template/hello.html" -->
               <!--  <templatePath>${basedir}/src/test/resources/strapdown.html.hbs</templatePath>-->
                 <outputPath>${basedir}/generated/document.html</outputPath>
                 <swaggerDirectory>${basedir}/generated/swagger-ui</swaggerDirectory>
                 <swaggerApiReader>com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader</swaggerApiReader>
                 <attachSwaggerArtifact>true</attachSwaggerArtifact>
              <!--   <modelConverters>io.swagger.validator.BeanValidator</modelConverters>-->
              </apiSource>
           </apiSources>
        </configuration>
        <executions>
           <execution>
              <phase>compile</phase>
              <goals>
                 <goal>generate</goal>
              </goals>
           </execution>
        </executions>
        <dependencies>
           <!-- Adding dependency to swagger-hibernate-validations to enable the BeanValidator as a custom
                model converter -->
           <dependency>
              <groupId>io.swagger</groupId>
              <artifactId>swagger-hibernate-validations</artifactId>
              <version>1.5.6</version>
           </dependency>
        </dependencies>
     </plugin>`

Error: [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.3:generate (default) on project ecp: Cannot load Swagger API reader: com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.3:generate (default) on project ecp: Cannot load Swagger API reader: com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214) at org.apache.maven.cli.MavenCli.main(MavenCli.java:158) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.MojoFailureException: Cannot load Swagger API reader: com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader at com.github.kongchen.swagger.docgen.mavenplugin.ApiDocumentMojo.execute(ApiDocumentMojo.java:123) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 19 more Caused by: com.github.kongchen.swagger.docgen.GenerateException: Cannot load Swagger API reader: com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader at com.github.kongchen.swagger.docgen.AbstractDocumentSource.getCustomApiReader(AbstractDocumentSource.java:389) at com.github.kongchen.swagger.docgen.mavenplugin.MavenDocumentSource.resolveApiReader(MavenDocumentSource.java:84) at com.github.kongchen.swagger.docgen.mavenplugin.MavenDocumentSource.loadDocuments(MavenDocumentSource.java:46) at com.github.kongchen.swagger.docgen.mavenplugin.ApiDocumentMojo.execute(ApiDocumentMojo.java:95) ... 21 more Caused by: java.lang.ClassNotFoundException: com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.github.kongchen.swagger.docgen.AbstractDocumentSource.getCustomApiReader(AbstractDocumentSource.java:381) ... 24 more

AlexElin commented 8 years ago

Hi, @javaworkinggirl If you use JAX-RS, delete com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader from plugin's configuration.

If you use Spring MVC, specify com.github.kongchen.swagger.docgen.reader.SpringMvcApiReader