0

When I run the project as a java application in eclipse it works perfectly but running a java -jar on windows cmd throws the SQL exception (No suitable driver found)

I have used maven(maven-assembly) to create the executable jar, a jar-with-dependencies is created in project\target. The postgresql jar (postgresql-42.2.5.jar) exists in the project\lib folder.

 <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.project.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>single</goal>
                  </goals>
                </execution>
            </executions>
        </plugin>

After running mvn clean package : A manifest file (project\src\main\resources\MANIFEST.mf) is copied into project\target\classes folder. The manifest file contains Class-Path: lib/postgresql-42.2.5.jar.

I have added the dependency in my pom.xml as well.

 <dependencies>
   <dependency>
     <groupId>postgresql</groupId>
     <artifactId>postgresql</artifactId>
     <version>${postgres.driver.version}</version>
   </dependency>
 </dependencies>

I was hoping that the Class-Path in manifest file would take care of this issue but it did not.

Might be a duplicate post but none of the existing solutions fixed my problem.

0 Answers0