Issue
I am using PostgreSQL for my java project. I downloaded the jar file and added it to build path of the project (configure build path > libraries > add external jar). It was working fine for several weeks as I worked on project, but when I went to run my project again a couple days ago I was getting this error:
java.lang.ClassNotFoundEcxeption: org.postgresql.Driver
I printed the class path (System.out.println(System.getProperty("java.class.path") and noticed that the PostgreSQL jar file is not on there, only the JUnit5 jar files are.This explains why I am getting the above class not found error.
So I tried to remove and re-add the jar file to the build path and re-run the program but it's still not working.
I have not changed the folder location of the jar file on my computer. I have another project using the same jar file and that one is functioning properly (jar file is also printing on class path for that project) but I can't figure out why Eclipse is not recognizing it on my current project now when it was working fine two days ago.
Solution
I would suggest to use a build tool like maven, gradle or similar. That kind of tool is perfect to avoid this type of issue. The two I suggested have support to be integrated with populars IDEs such as eclipse, intellij and else. Having a build tool, will let you define all the dependencies that your project needs without having to download and link them manually. It also have more features like running automated test, compile, build and package the project, make a deploy, etc.
I would also suggest tu use sdkaman that will let you install different versions and do upgrades at any moment you want
Answered By - Gastón Schabas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.