You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Kartik Singhal <gk...@gmail.com> on 2015/07/03 09:13:21 UTC

Maven NoClassDefFound Error

Hi

I am working on a maven project on NetBeans and binding it in jar using
Maven Jar plugin.
While working on NetBeans the project runs fine, but when I run its .jar
file its gives the following error

Exception in thread "main" java.lang.NoClassDefFoundError:
org/elasticsearch/index/query/QueryBuilder
    at org.dbpedia.keywordsearch.uinterface.uiclass.main(uiclass.java:31)
Caused by: java.lang.ClassNotFoundException

Now I know it is because of class path. I tried to edit the class path with
the default local repository of maven but still it shows the same error.

My pom file looks like this:

 <modelVersion>4.0.0</modelVersion>
    <groupId>org</groupId>
    <artifactId>KeywordSearch</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>0.20.6</version>
        </dependency>
     </dependencies>
     <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
     </properties>
     <build>
         <plugins>
          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                 <configuration>
                 <archive>
                  <manifest>

<mainClass>org.keywordsearch.uinterface.uiclass</mainClass>
                       <addClasspath>true</addClasspath>

<classpathPrefix>/home/enigmatus/.m2/repository/</classpathPrefix>
                   </manifest>
                  </archive>
                </configuration>
            </plugin>
          </plugins>
    </build>

Can anybody tell me where I am going wrong.
Also I have to deploy my project, so how to change the path of default
local repository of maven dependencies where they are saved and then I can
access the dependencies using class-path from there.

Thanks
Cheers
Kartik

Re: Maven NoClassDefFound Error

Posted by Robert Patrick <ro...@oracle.com>.
You should really try the Users mailing list, as this list is reserved for Maven developers...

It's not clear at all what you are trying to do.  In Maven, when you build your project into a JAR, that JAR will only contain the code from the project so to run that JAR (and not any of the dependencies), you will need to make sure that the CLASSPATH is properly set before running the JAR.  

If you want to create a self-contained JAR that includes all of the dependencies, you should use the assembly plugin rather than the JAR plugin.

Robert Patrick <ro...@oracle.com>
VP, Development, Oracle
Mobile: +1 469 556 9450
Sent from my iPad

> On Jul 3, 2015, at 2:13 PM, Kartik Singhal <gk...@gmail.com> wrote:
> 
> Hi
> 
> I am working on a maven project on NetBeans and binding it in jar using
> Maven Jar plugin.
> While working on NetBeans the project runs fine, but when I run its .jar
> file its gives the following error
> 
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/elasticsearch/index/query/QueryBuilder
>    at org.dbpedia.keywordsearch.uinterface.uiclass.main(uiclass.java:31)
> Caused by: java.lang.ClassNotFoundException
> 
> Now I know it is because of class path. I tried to edit the class path with
> the default local repository of maven but still it shows the same error.
> 
> My pom file looks like this:
> 
> <modelVersion>4.0.0</modelVersion>
>    <groupId>org</groupId>
>    <artifactId>KeywordSearch</artifactId>
>    <version>1.0.0</version>
>    <packaging>jar</packaging>
>    <dependencies>
>        <dependency>
>            <groupId>org.elasticsearch</groupId>
>            <artifactId>elasticsearch</artifactId>
>            <version>0.20.6</version>
>        </dependency>
>     </dependencies>
>     <properties>
>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>        <maven.compiler.source>1.7</maven.compiler.source>
>        <maven.compiler.target>1.7</maven.compiler.target>
>     </properties>
>     <build>
>         <plugins>
>          <plugin>
>                <groupId>org.apache.maven.plugins</groupId>
>                <artifactId>maven-jar-plugin</artifactId>
>                <version>2.4</version>
>                 <configuration>
>                 <archive>
>                  <manifest>
> 
> <mainClass>org.keywordsearch.uinterface.uiclass</mainClass>
>                       <addClasspath>true</addClasspath>
> 
> <classpathPrefix>/home/enigmatus/.m2/repository/</classpathPrefix>
>                   </manifest>
>                  </archive>
>                </configuration>
>            </plugin>
>          </plugins>
>    </build>
> 
> Can anybody tell me where I am going wrong.
> Also I have to deploy my project, so how to change the path of default
> local repository of maven dependencies where they are saved and then I can
> access the dependencies using class-path from there.
> 
> Thanks
> Cheers
> Kartik