0

Use Apache Netbeans 12, have this project structure : Structure

then build to jar with this pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>apps</artifactId>
    <version>1.0</version>
    
    <packaging>jar</packaging>

<build>
    <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.4</version>
          <configuration>
              <archive>
                  <manifest>
                      <mainClass>com.selfcompany.apps.Login</mainClass>
                  </manifest>
              </archive>
          </configuration>
      </plugin>
  </plugins>
</build>
    <dependencies>
        <dependency>
            <groupId>com.1stleg</groupId>
            <artifactId>jnativehook</artifactId>
            <version>LATEST</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20190722</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.0-801.jdbc4</version>
</dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>7</maven.compiler.source>
        <maven.compiler.target>7</maven.compiler.target>
    </properties>
    <name>apps</name>
</project>

when run with this command :

java -jar apps.jar

got error

java.sql.SQLException: No suitable driver found for jdbc:postgresql:

error like missing lib postgresql.jar, but already on pom.xml, there on Dependencies folder. Anyone advices ? because when running from IDE working fine

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
blinkbink
  • 89
  • 5
  • Why are you using an ancient version (9.0-801.jdbc4) of the PostgreSQL JDBC driver? The latest version is 42.2.14. In any case, judging by the error message, one of the problem is that your JDBC url is currently `jdbc:postgresql:` which is not a valid JDBC url. The other is that your pom doesn't define the class path in the manifest, so the driver is not present at runtime. – Mark Rotteveel Aug 13 '20 at 05:55
  • do you have example define manifest the postgres in pom? i have try add this : org.postgresql postgresql 9.1-901-1.jdbc4 – blinkbink Aug 13 '20 at 06:42
  • See the first duplicate for how to define the class path in the manifest. As to the coordinates of the PostgreSQL JDBC driver, see https://search.maven.org/artifact/org.postgresql/postgresql/42.2.14/jar – Mark Rotteveel Aug 13 '20 at 07:05

0 Answers0