我正在构建一个多模块的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.ApiOriginFilterAPIOriginFilter是在MyAppSchemas模块中生成的类。我已经将MyAppSchemas jar作为依赖项包含在MyAppWs中:
<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运行时类路径中包括其他子模块?
发布于 2017-04-19 23:34:09
这可以通过将类添加到外部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>https://stackoverflow.com/questions/43505801
复制相似问题