无法使用Swagger + Maven + Servlet + Tomcat打开index.html

时间:2016-11-02 22:11:18

标签: json maven tomcat servlets swagger

我正在尝试将Swagger集成到我的Tomcat-Servlet-Application中。我将swagger-ui的dist文件夹的所有文件复制到我的Servlet应用程序的web文件夹中,并调整了web.xml和pom.xml。我正在使用Eclipse和Maven。我只是无法打开index.html,尽管Tomcat服务器返回了swagger.json内容。

我的pom.xml如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0"    
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Ch</groupId>
<artifactId>Ch</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <warSourceDirectory>WebContent</warSourceDirectory>
      <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
  </plugin>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.10</version>
</dependency>
</dependencies>
</project>

我的web.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns="http://xmlns.jcp.org/xml/ns/javaee"  
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org 
/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>Ch</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
  <servlet>
    <servlet-name>jersey</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>
            io.swagger.jaxrs.listing.ApiListingResource,
            io.swagger.jaxrs.listing.SwaggerSerializers,
            test.SwaggerApplication
        </param-value>
    </init-param>
</servlet>


<servlet-mapping>
    <servlet-name>jersey</servlet-name>
    <url-pattern>/ch/*</url-pattern>
</servlet-mapping>
    <servlet>
    <servlet-name>Jersey2Config</servlet-name>
    <servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
            <init-param>
        <param-name>api.version</param-name>
        <param-value>1.0.0</param-value>
    </init-param>
    <init-param>
        <param-name>swagger.api.basepath</param-name>
        <param-value>http://localhost:8080/Ch/ch</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

我的index.html包含以下行:

} else {
    url = "http://localhost:8080/Ch/ch";
  }

修改

我意识到我的WebContent / WEB-INF / lib文件夹是空的......

提前致谢

0 个答案:

没有答案