0

Edit: I am using Spring Framework which means my application has an embedded Tomcat Servlet. I am then using the following gradle command to compile my application into an executable JAR file: ./gradlew clean build I deploy this file to my server and execute it using this command SERVER_PORT=9090 java -jar gs-rest-service-0.3.0.jar Please note that this works fine without the database included in the JAR file (i.e. I can make HTTP requests and pass back information). My problem consists with the Exception error message I receive below.

I'm trying to connect my executable JAR file to my database but I keep getting this error: java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost/projectdb

From research into previous questions I understand that I may need to add or SET the classpath for the JDBC jar file so that when the JAR file executes it knows where to find it. However I don't know how to do this and other answers seem unclear.

I'm using Postgresql and I'm trying to implement this on my server using Ubuntu 14.04. This works fine on my local machine but that's because the JDBC is included as a referenced library. Here is a snippet of code from the log.

java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost/projectdb
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at server.DatabaseAccessor.<init>(DatabaseAccessor.java:31)
at server.controllers.ActivityController.<init>(ActivityController.java:18)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)

Any useful help and information would be grateful. Thanks.

  • 4
    http://stackoverflow.com/questions/5130254/java-error-no-suitable-driver-found did you check this? – AhmetRasitBekar Dec 19 '15 at 13:09
  • Which IDE are you using, and how did you build the JAR file? – JonK Dec 19 '15 at 13:26
  • @JonK I'm using Eclipse Luna and I'm performing a ./gradlew clean build which generates my JAR file. – ubiquitous23 Dec 19 '15 at 14:11
  • How exactly are you starting your application? Please edit your question and add the **exact** command you use. –  Dec 19 '15 at 16:15
  • `java -jar gs-rest-service-0.3.0.jar` only puts `gs-rest-service-0.3.0.jar` on the classpath and any library defined in your MANIFEST.MF. So what is the classpath defined in the manifest of `gs-rest-service-0.3.0.jar`? –  Dec 19 '15 at 18:54
  • @a_horse_with_no_name I don't have anything in the MANIFEST.MF file (just to be certain, that is the MANIFEST.MF file located in the build/tmp/ folder?) – ubiquitous23 Dec 19 '15 at 19:12
  • The MANIFEST is part of the .jar file –  Dec 19 '15 at 19:47
  • @a_horse_with_no_name Ok, so do you know how I go about editing this MANIFEST file and what should I put in it? Thanks – ubiquitous23 Dec 19 '15 at 19:56

0 Answers0