Category Archives: maven

java.lang.NoClassDefFoundError maven project

1. Symptom

Maven project build well but get failure when running in eclipse with the issue

java.lang.NoClassDefFoundError

2. Cause
This issue happen cause jars files is missing at run-time. It do not deploy properly in eclipse when running.

3. Fix
You can right click to project and choose Properties->Deployment Assembly and make sure Maven Dependencies in list

eclipse-project-deployment-assembly

Maven to download dependencies

When you use maven to build and manage dependencies on a project and you want supply that project to other project without maven, i am sure you will get a question how i can copy all libraries this project depend on? In this post i will show you how to use maven to download dependencies.
To do that i using maven plugin Copying project dependencies. I add following lines to my pom.xml file

<build>
    <plugins>
        <!--other plugin--->
         .....
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

With this config when we do maven -install command it will  copy all libraries that project is depended to target/lib folder.

Eclipse Web Application and Maven Dependency Issues

When development web application in eclipse and use maven to manage dependency we usually face with some problem as missing library at runtime cause maven dependency issues. In this post i show you how to dianostic that issue.
Step 1. Enable/disable Maven feature
On Eclipse IDE, right click on the project, choose maven->Disable Maven Nature
disable-maven-nature
After that right click on project choose Configure-> Convert to maven project

convert-to-maven-project
If you already do this step but no luck, move to step 2
Step 2. Clean and update project
Some time you get exception cause library download by maven get corrupt cause network issue. Check log on console tab carefully to find what library have issue and go to maven local repository to delete that library(you can also delete all). Normal maven local repository lay on %USERPROFILE%/.m2
Next, In Eclipse IDE right click choose maven->update project

update-maven-project

If your project still not work when run, go to next step.

Step 3. Checking Deployment Assembly
Right click on project in Eclipse IDE, choose properties and choose Deployment Assembly. Please make sure your project have minimal as below if you don’t using any other library in WEB-INF/lib. If you using more you can manuall add to Deployment Assembly by click Add button.

project-deployment-assembly