13

I am running a spring project with maven and I am trying to use postgresql. I've added the dependency to pom.xml, but at tomcat startup, I get the following error:

java.lang.ClassNotFoundException: org.postgresql.Driver

pom.xml dependency:

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>9.3-1101-jdbc41</version>
</dependency>

It appears that Maven isn't downloading the jar so the Driver class is not found. Any ideas?

Alex
  • 312
  • 1
  • 3
  • 9
  • Did you got warnings during your build? Are you behind a proxy? Have you checked if the artifacts has been downloaded or not? – khmarbaise Mar 11 '14 at 16:40

7 Answers7

11

What also worked for me if you are on intellj: right klick pom.xml->Maven->Reimport Don't know why it doesn't download the artifact on copy paste.

FishingIsLife
  • 1,972
  • 3
  • 28
  • 51
5

When I put this in my pom, the artifact gets downloaded. Maybe you should clean your maven repository cache or delete the folders manually and retry.

Stefan
  • 12,108
  • 5
  • 47
  • 66
2

If you came here for "missing artifact" error, This worked for me:

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4.1212</version>
    </dependency>

For PostgreSQL 10 I use this:

       <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.1.4</version>
        </dependency>
Ismail Yavuz
  • 6,727
  • 6
  • 29
  • 50
1

Try to rebuild the artifact, most likely only the added dependency was not included there

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 08 '22 at 10:10
0

Maven wasn't recognizing the new dependency I have added to pom.xml, so I added it through 'Dependency view' from the xml and that did the trick. Thank you for your answers.

Alex
  • 312
  • 1
  • 3
  • 9
0

In my case, the problem was from the <minimizeJar>true</minimizeJar> configuration option for the maven-shade-plugin.

Previously, I set this configuration to true to make my shaded JAR file smaller due to the 10MB limit on AWS Lambda application.

After trying everything on SOF and nothing worked, I tried commenting out the minimizeJar option and it just worked flawlessly...


This is my working config for maven-shade-plugin:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.4.1</version>
  <configuration>
    <createDependencyReducedPom>false</createDependencyReducedPom>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
      <!-- <configuration>
        <minimizeJar>true</minimizeJar>
      </configuration> -->
    </execution>
  </executions>
</plugin>

I ran the Maven project using the following steps:

  1. mvn clean package && mvn clean install
  2. java -cp target/example-1.0.0.jar com.example.mainClassName
Quan Bui
  • 175
  • 1
  • 13
-1

You need to place a copy of the jar in the tomcat/lib folder.

John F.
  • 4,780
  • 5
  • 28
  • 40
  • 1
    Tomcat manages the connections? No. Tomcat is a servlet engine but not an application server like Glassfish, JBoss, Weblogic etc. – khmarbaise Mar 11 '14 at 16:41
  • This will not change a thing, cause the best in such cases is to put the driver into the resulting war file which will be deployed. That's it. – khmarbaise Mar 11 '14 at 16:46