Karlo Kraljic February 2016

CouchDB4j/ mvn dependencies are missing

I am having trouble setting up a connection to my local CouchDB programmatically.

I am using couchDb4j- and things seem to look good, until I run and try to connect to the DB.

My console is throwing the following error:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/http/params/HttpParams
[...]
Caused by: java.lang.ClassNotFoundException: org.apache.http.params.HttpParams

Since my small application is not finding a class, I've checked my dependencies- everything should be fine. I have:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.0-beta3</version>
</dependency>
<dependency>
    <groupId>commons-httpclient</groupId>
    <artifactId>commons-httpclient</artifactId>
    <version>3.1</version>
</dependency>

Which should include all necessary http specific .jar (especially the first one should include the httpParams binaries; source: http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.0-beta3 ).

To prevent from including wrong binaries cached on my system, I am running the following:

mvn clean && mvn package

I've also deleted my .m2 folder.

Googling around gave me the hint that my classpath may be wrong leading to missing dependencies in runtime. But I have set up my classpath in my pom; see here:

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
         

Answers


sunny February 2016

Add these dependencies inside plugin declaration like this:

<plugin>
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <dependencies>
  ...
 </dependencies>
</plugin>

Plugins have their own classpath


Karlo Kraljic February 2016

Found the solution.

The problem were missing dependencies during execution.

To make sure, that all necessary files are binded during runtime, I had to include the following plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.6</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

which, if I got it right, binds on an "uber" jar all dependencies... Source: https://maven.apache.org/plugins/maven-shade-plugin/

Post Status

Asked in February 2016
Viewed 1,378 times
Voted 6
Answered 2 times

Search




Leave an answer