如何使用Eclipse& amp;来解决ClassNotFoundException Intellij IDEA?

时间:2016-01-20 12:34:45

标签: java eclipse maven intellij-idea classnotfoundexception

我们有小团队,我们使用Eclipse和Intellij IDEA。 我们也使用Maven模块。

当Idea将一些数据推送到git并且Eclipse提取数据时,我们遇到了一些问题。

SEVERE: StandardWrapper.Throwable java.lang.NoClassDefFoundError: com/epam/freelancer/business/context/ApplicationContext
at com.epam.freelancer.web.controller.FrontController.init(FrontController.java:38)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4944)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.ClassNotFoundException: com.epam.freelancer.business.context.ApplicationContext
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1295)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1147)
... 13 more   

此异常仅出现在Eclipse中,而不出现在Idea中。 我花了8个多小时来解决这个问题,但没有任何改变。

项目结构
家长 - 自由职业者
孩子的:
 的 数据库
 业务
 安全
 web
- 我在Tomcat中部署此模块

荧光棒:
父母:

<modelVersion>4.0.0</modelVersion>
<groupId>com.epam</groupId>
<artifactId>freelancer</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Freelancer</name>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<modules>
    <module>web</module>
    <module>database</module>
    <module>business</module>
    <module>security</module>
</modules>   

模块poms
网络模块

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.epam</groupId>
    <artifactId>freelancer</artifactId>
    <version>1.0</version>
</parent>

<artifactId>web</artifactId>
<packaging>war</packaging>
<name>web</name>

<build>
    <finalName>web</finalName>
</build>

<dependencies>
    <dependency>
        <groupId>com.epam</groupId>
        <artifactId>security</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

安全模块

    <modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.epam</groupId>
    <artifactId>freelancer</artifactId>
    <version>1.0</version>
</parent>

<artifactId>security</artifactId>

<dependencies>
    <dependency>
        <groupId>com.epam</groupId>
        <artifactId>business</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

业务模块

    <modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.epam</groupId>
    <artifactId>freelancer</artifactId>
    <version>1.0</version>
</parent>

<artifactId>business</artifactId>
<build>
    <finalName>business</finalName>
</build>

<dependencies>
    <dependency>
        <groupId>com.epam</groupId>
        <artifactId>database</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

3 个答案:

答案 0 :(得分:0)

您应该检查Eclipse中的Java EE模块依赖项(右键单击您的动态Web项目,转到Properties&gt; Deployment Assembly)

答案 1 :(得分:0)

<parent>
    <groupId>com.groupName</groupId>
    <artifactId>id</artifactId> 
    <version>1.0-SNAPSHOT</version>
    <relativePath>../parent</relativePath>
</parent>

这是我在Maven儿童pom中的一个例子。我使用的结构是:
/common/parent/pom.xml
/common/child/pom.xml

在我的父项目中,我设置了这样的模块的路径:

<modules>
    <module>../childModule</module>
</modules>

我使用NetBeans,但我希望它对您有用。

答案 2 :(得分:0)

尝试将org.apache.catalina依赖项添加到您的POM中。 Stacktrace看起来像Maven找不到Catalina