【发布时间】:2017-04-19 20:50:44
【问题描述】:
我正在构建一个多模块 Maven Web 应用程序项目,但在我的 Tomcat 服务器上部署 WAR 时遇到问题。
我的项目结构是
- 我的应用程序
- MyAppSchemas
- MyAppUtils
- MyAppWs
这就是问题所在。当我尝试在本地 Tomcat 服务器上部署生成的战争时,我收到以下错误:
Apr 19, 2017 1:42:43 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter ApiOriginFilter
java.lang.ClassNotFoundException: io.swagger.api.ApiOriginFilter
APIOriginFilter 是在 MyAppSchemas 模块中生成的一个类。我已将 MyAppSchemas jar 作为依赖项包含在 MyAppWs pom 中:
<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>
<parent>
<groupId>io.swagger</groupId>
<artifactId>MyApp</artifactId>
<version>1.0</version>
</parent>
<artifactId>MyAppWs</artifactId>
<name>MyAppWs</name>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>APP-INF/lib</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>MyAppSchemas</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>MyAppUtils</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
底线:如何在我的战争运行时类路径中包含其他子模块?
【问题讨论】:
-
我不相信它会有所作为,但删除
maven-war-plugin配置。在 Tomcat 上下文中,这完全是一派胡言。然后在执行mvn clean install后,验证您的依赖jar 是否已放置在构建WAR 文件过程中生成的MyAppWs/target/MyAppWs/WEB-INF/lib目录中。
标签: java maven tomcat swagger war