title: Using postgresql driver with Maven
body: <p>I tried to use following dependency in Maven:</p>
  
  <pre><code>&lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;version&gt;9.4-1200-jdbc4&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>When I used this driver in the main method, it works, but when I installed the module and tried to run the .jar file, a ClassNotFoundException occurs. What should I do?</p>
  
  <p>I call the driver in the runtime by Class.forName("org.postgresql.Driver"). I tried to change the scope in dependency to runtime, but it didn't help.</p>
  
  <p>My stacktrace:</p>
  
  <pre><code>java.lang.ClassNotFoundException: org.postgresql.Driver
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:191)
      at dbchecker.CountDBChecker.openConnection(CountDBChecker.java:149)
      at dbchecker.CountDBChecker.main(CountDBChecker.java:165)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  </code></pre>
  
  <p>I used the jar by command java -jar and also in iPOJO (like in <a href="http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-hello-word-maven-based-tutorial.html" rel="nofollow">this</a> tutorial).</p>
  
  <p>I resolved problem with jar executing by maven-assembly-plugin, but I have another connected problem with iPOJO. The jar is not executed by iPOJO and it seems like some instructions in manifest file are missing. Previous manifest:</p>
  
  <pre><code>Manifest-Version: 1.0
  Export-Package: dbchecker;uses:="common,checker.service";version="1.0.
   0"
  iPOJO-Components: instance { $component="dbchecker.CountDBChecker" }co
   mponent { $name="dbchecker.CountDBChecker" $classname="dbchecker.Coun
   tDBChecker" provides { }manipulation { $classname="dbchecker.CountDBC
   hecker" interface { $name="checker.service.CheckerService" }field { $
   name="connection" $type="java.sql.Connection" }field { $name="dateCol
   umn" $type="java.lang.String" }field { $name="dateFrom" $type="java.l
   ang.String" }field { $name="dateTo" $type="java.lang.String" }field {
    $name="interval" $type="long" }field { $name="maxRequired" $type="lo
   ng" }field { $name="minRequired" $type="long" }field { $name="report"
    $type="common.Report" }field { $name="send" $type="boolean" }field {
    $name="table" $type="java.lang.String" }field { $name="zdegeokodowan
   o" $type="common.Zdegeokodowano" }field { $name="zdegeokodowanoColumn
   " $type="java.lang.String" }method { $name="$init" }method { $name="g
   etInterval" $return="long" }method { $name="check" $return="common.Re
   port" }method { $name="buildCountQuery" $return="java.lang.String" }m
   ethod { $name="executeCountQuery" $return="long" $arguments="{java.la
   ng.String}" $names="{query}" }method { $name="setMessage" $return="ja
   va.lang.String" $arguments="{long,java.lang.String}" $names="{result}
   " }method { $name="setErrorMessage" $return="java.lang.String" $argum
   ents="{long,java.lang.String,long,boolean}" $names="{result,query,req
   uired}" }method { $name="reportErrorMessage" $arguments="{long,java.l
   ang.String,long,boolean}" $names="{result,query,required}" }method { 
   $name="openConnection" $return="java.sql.Connection" }}}
  Bundle-Version: 1.0.0
  Built-By: mk
  Build-Jdk: 1.7.0_79
  Tool: Bnd-1.50.0
  Bundle-Name: countDBChecker
  Bnd-LastModified: 1442913271587
  Created-By: Apache Maven Bundle Plugin &amp; iPOJO 1.12.1
  Bundle-ManifestVersion: 2
  Import-Package: org.osgi.service.log;version=1.3, common;version="[1.0
   ,2)", org.apache.felix.ipojo.architecture;version="[1.12.1,2.0.0)", c
   hecker.service;version="[1.0,2)", org.apache.felix.ipojo;version="[1.
   12.1,2.0.0)", org.osgi.service.cm;version=1.2
  Bundle-SymbolicName: supervisor.countDBChecker
  </code></pre>
  
  <p>Recent manifest:</p>
  
  <pre><code>Manifest-Version: 1.0
  Created-By: 24.79-b02 (Oracle Corporation)
  Archiver-Version: Plexus Archiver
  </code></pre>
  
  <p>Should I change the execution goal in my pom.xml? This is the pom (part):</p>
  
  <pre><code>            &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-ipojo-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;ipojo-bundle&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.4&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;descriptorRefs&gt;
                          &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
                      &lt;/descriptorRefs&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;make-assembly&lt;/id&gt;
                          &lt;phase&gt;install&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;single&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  </code></pre>