I have a maven web application with tomkat. I want to use a database in my application. In the dependencies, I specify everything correctly, but for some reason the java.lang.ClassNotFoundException: org.postgresql.Driver error occurs java.lang.ClassNotFoundException: org.postgresql.Driver in Class.forName("org.postgresql.Driver"); . Piece of dependencies:

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

I created a new regular application (without tomkata and servhelets), indicated the same thing in dependencies. Rewrote there a piece to work with the database. And the application works correctly. Why and what to do? Run all of IntelliJ.

pom.xml:

 <dependencies> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.2.5</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.3</version> <scope>provided</scope> </dependency> </dependencies> <properties> <maven.compile.source>1.8</maven.compile.source> <maven.compile.target>1.8</maven.compile.target> </properties> 

I put it this way: I compile it in IntelliJ, then from out I transfer it to a folder in the webapps . Or I launch at once from IntelliJ.

  • How are you on Tomsk Deplote? jar collect with all addictions or lightly? - Senior Pomidor
  • @SeniorPomidor with dependencies - Anton Sorokin
  • show your pom and how you collect - Senior Pomidor
  • forgot plus +) - Stranger in the Q

1 answer 1

The postgresql driver needs to be put in the tomkata lib unfortunately or fortunately - that’s up to you, it always hurt me. I don’t know how things are now with this, I haven’t done more than 5 tomkat in the wild, It used to be so before.

PS: It is googled

  • Yes, thanks, it worked - Anton Sorokin
  • @AntonSorokin and what are you Tomkato? - Stranger in the Q
  • I have 9, the last - Anton Sorokin
  • @AntonSorokin means nothing has changed in the Danish kingdom - Stranger in the Q
  • @AntonSorokin a what should have changed? It is necessary to do the right thing - to prescribe packaging war, add a war plugin, especially if the project is unconventionally created and prescribe everything, where to get, register the osprey correctly (for the same driver), and build the project not by build, but by maven ' Om, then there will be a normal war'nik, which is deployed to the Tomcat (if by http, then it can be directly maven and deployed using the appropriate plugin). In general, all this is elementary done. - keekkenen