0

I have a .jar file(insertdata.jar) which has a dependency with postgresql-42.2.23.jar.I have included main class in the Manifest file also. Currently both of these files are located inside C:\Users\yush\Desktop\java directory. I have tried to run insertdata1.jar file with following command in the command line.

java -jar C:\Users\yush\Desktop\java\insertdata1.jar

with this command I'm getting following error, which seems it is unable to access postgresql-42.2.23.jar classes.

java.lang.ClassNotFoundException: org.postgresql.Driver

My question is how do I run insertdata1.jar file in the command line with postgresql-42.2.23.jar?

  • 1
    The short answer is that you can't. `java -jar ...` doesn't allow you to tinker with the classpath. For alternative approaches (that will work), see https://stackoverflow.com/questions/183292/classpath-including-jar-within-a-jar – Stephen C Sep 21 '21 at 08:08

1 Answers1

1

2 options for you

  1. change your invocation java -cp <class-path-of-all-required-jars> <Main.class>

  2. build uber/fat jar - combines all individual jars. then you can so your -jar thing

PrasadU
  • 2,154
  • 1
  • 9
  • 10