0

Maven Version: 4

I am writing an annotation processing program that will take tableName and find their columns.

However, the program saying java.lang.ClassNotFoundException: org.postgresql.Driver.

I have added postgresql in pom.xml but still saying class not found. Tried a different postgresql dependency version too. When I create a simple maven program then it does not complain but in the case annotation processing project, I am getting this error.

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



Class.forName("org.postgresql.Driver");
        connection = DriverManager.getConnection(
                "jdbc:postgresql://localhost:5432/db-name?sslmode=disable","user","pass");

I even tried to load the postgresql jar using java but no lo luck. Tried these to load jar dynamically: How to load JAR files dynamically at Runtime?

Is there a scenario in the case of an annotation processing program that I am missing?

UPDATE I found the issue. annotation-processing-project is working fine. The other project (where I was adding annotation-processing-project as a dependency) also has postgresql dependency and the scope was runtime.

<dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>

This was causing annotation-processing-project to find the postgresql.

Ho can I not edit client project and annotation-processor-project gets the postgresql dependency too??

3
  • Does this answer your question? Maven 3 - How to add annotation processor dependency? Commented Jul 15, 2021 at 11:47
  • Does this answer your question? What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException? Commented Jul 16, 2021 at 7:51
  • @9ilsdx9rvj0lo That is not my question. I have created an annotation-processing program that internally uses postgresql(maven dependency). I have one project(client), In this client project adding annotation-processing as a dependency. Now the problem: Client project also has postgresql dependency and scope is runtime. now whenever I try to build a client project annotation-processing says class not found org.postgresql.Driver. because the client has set postgresql dependency scope runtime and annotation-proecssing program runs at compile time. Commented Jul 16, 2021 at 10:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.