简体   繁体   中英

How to solve ClassNotFoundException using Eclipse & Intellij IDEA?

We have small team and we use Eclipse and Intellij IDEA. We use Maven Modules too.

When Idea push some data to git and Eclipse pull data we have several problems.

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   

This exception appear only in Eclipse not in Idea. I spent more than 8 hours to solve this problem but nothing changed.

Project structure
parent - freelancer
childs:
database
business
security
web - I deploy this module in Tomcat

Poms:
parent:

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

And modules poms
Web module

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

Security module

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

Business module

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

您应该在Eclipse中检查Java EE模块的依赖关系(右键单击动态Web项目,转到“属性”>“部署程序集”)

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

This is an example I had in a Maven child pom. The structure I used was:
/common/parent/pom.xml
/common/child/pom.xml

And in my parent project I set the path to the modules like this:

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

I used NetBeans, but I hope it could be useful for you.

Try to add org.apache.catalina dependency to your POM. Stacktrace looks like Maven can't find Catalina .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM