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.