简体   繁体   中英

NoClassDefFoundError on Maven dependency if target folder is not present

Currently my NetBeans 8.0 has been doing the strangest thing.

I have a multimodule project. Usually I did not even have to have the projects opened or even downloaded, if the modules were in maven repository. Currently, some of my modules however need to be opened and built, so that "target" folder is in the project directory filled with classes. If it is not, I get a NoClassDefFoundError.

The error looks like this:

Exception in thread "main" java.lang.NoClassDefFoundError: SOME/CLASS/THAT/IS/EXPECTED/IN/TARGET/FOLDER/OF/SOME/MODULE/THAT/IS/A/DEPENDENCY
at ...
Caused by: java.lang.ClassNotFoundException: com.example.SOME.CLASS.THAT.IS.EXPECTED.IN.TARGET.FOLDER.OF.SOME.MODULE.THAT.IS.A.DEPENDENCY
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

My POM looks like this:

<parent>
    <groupId>some</groupId>
    <artifactId>parent</artifactId>
    <version>0.9-SNAPSHOT</version>
</parent>

<scm>
    <developerConnection>scm:svn:https://someconnection</developerConnection>
</scm>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <configuration>
                <tagBase>sometagbase/tags</tagBase>
            </configuration>
        </plugin> 
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    <dependency>
        <groupId>myModuleGroupId</groupId>
        <artifactId>somModule1</artifactId>
        <version>1.2.1-SNAPSHOT</version>
        <type>jar</type>
    </dependency>
      ...... many of these here
</dependencies>

Why does it suddenly require a target folder with classes? Is it not supposed to get them from the dependencies? From the repository?

Open maven tab at right side of the editor and run double click all options of life cycle and try to see if folder finally generated

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