我正在构建一个多模块Maven Web应用程序项目,但是我在Tomcat服务器上部署WAR时遇到了问题。
我的项目结构是
这就是问题所在。当我尝试在我的本地Tomcat服务器上部署生成的war时,出现以下错误:
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>
结论:我如何在war运行时类路径中包含其他子模块?
答案 0 :(得分:0)
这可以通过将您的类添加到外部jar并将其标记为依赖项来实现。
通过系统范围添加依赖关系
<dependency>
..
<scope>system<scope>
<systemPath>your jar path</systemPath>
</dependency>
然后使用下面的插件定义
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<includes>
<include>directory path/*.jar</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>