首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ClassNotFound Maven战争

ClassNotFound Maven战争
EN

Stack Overflow用户
提问于 2017-04-19 20:50:44
回答 1查看 1.1K关注 0票数 0

我正在构建一个多模块的Maven web应用程序项目,但在我的Tomcat服务器上部署WAR时遇到了困难。

我的项目结构是

  • MyApp
    • MyAppSchemas
    • MyAppUtils
    • MyAppW

问题出在这里。当我试图在本地Tomcat服务器上部署生成的war时,我会得到以下错误:

代码语言:javascript
复制
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中:

代码语言:javascript
复制
<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运行时类路径中包括其他子模块?

EN

回答 1

Stack Overflow用户

发布于 2017-04-19 23:34:09

这可以通过将类添加到外部jar并将其标记为依赖来实现。

通过系统作用域添加依赖项

代码语言:javascript
复制
<dependency>
   ..
   <scope>system<scope>
   <systemPath>your jar path</systemPath>
</dependency>

然后使用插件定义如下所示

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43505801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档