2017-04-19 64 views
0

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

我的项目结构是

  • MyApp的
    • 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罐子作为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> 

底线:我怎么有我的战争运行时类路径等子模块?

+0

我不相信它一定会有所作为,但删除'Maven的战争插件然后定义'配置。这在Tomcat中是完全无稽之谈。然后在执行'mvn clean install'后,确认您的依赖jar已经放置在构建WAR文件的过程中生成的MyAppWs/target/MyAppWs/WEB-INF/lib目录中。 –

回答

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> 
+0

我明白你的意思,但不应该有办法处理这只是maven子模块的依赖关系? – Jack

+0

通常这种风格是遵循的,因为当我们需要引用自定义类时它是灵活的。 – BalajiK