jule64
jule64

Reputation: 487

NoClassDefFoundError after converting simple java project to maven project in eclipse

I have a class that I coded in a standard java project in eclipse on OSX (Java 1.6). The class uses classes and interfaces from another library.
I select the class, then do Run As > Java Application and all works well.

After that I try to run my project as a Maven project and things start to get a little frustrating.. I summarise all the steps here hoping that someone will tell me what I am doing wrong: - From the standard java project I right click and did Configure > Convert to Maven project and clicked Finnish. All good so far.

I don't know where to go from here. You can imagine that I went through a lot of trials and errors and searched on SO and elsewhere to find a way to get this to work. But I just cannot figure out what is wrong. So if someone has an idea I am so ready to listen.

I am pasting below my directory layout from the Navigator View as well as from the Package explorer view

layout Navigator view

enter image description here

And here is the POM.xml where I have added the JRE config

<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>
  <groupId>someproject</groupId>
  <artifactId>someproject</artifactId>
  <version>1.0-SNAPSHOT</version>
    <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Upvotes: 0

Views: 2276

Answers (1)

Abhinav Sarkar
Abhinav Sarkar

Reputation: 23812

The project directory structure does not match with the default Maven directory structure. Maven expects the source to be in src/main/java directory under the root folder (the folder containing pom.xml). The source here is in the src folder hence the No sources to compile error.

You can either move your sources to use the default Maven directory structure or change the pom.xml to explicitly specify your source directory by adding the following to the build section of the pom:

<sourceDirectory>${basedir}/src</sourceDirectory>

More info on Maven's standard directory layouts can be found here.

Upvotes: 7

Related Questions