0

I've been building a small program with friends. We have been using JavaFX for the program and are too late to use OpenJFX, thus making us use JDK 1.8.0. We are using Maven to compile everything and compiles successfully.

The issue is that when we go to the folder of the .jar, when we try to open it with this line java -jar Medical-Application.jar, we get a No suitable driver found for jdbc:sqlite:(my path to DB).

We already tried to add Class.forName("org.sqlite.JDBC"); but it didn't work.

Here is the POM file.

<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>TP3.projet-session</groupId>
  <artifactId>medical-project</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>medical-project</name>
  <url>http://maven.apache.org</url>
  <developers>
    <developer>
        <id>aville</id>
        <name>ArnaudVillemaire</name>
        <email>villemaire.arnaud@gmail.com</email>
    </developer>
  </developers>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <javafx.version>2.2</javafx.version>
  </properties>
  <build>
        <plugins>
            <plugin>
                <!-- copy all dependencies of your app to target folder-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <configuration>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <!-- define the deploy ANT task-->
                                <taskdef name="jfxdeploy" classname="com.sun.javafx.tools.ant.DeployFXTask"
                                    classpathref="maven.plugin.classpath" />
                                <!-- define the JarSing ANT task-->
                                <taskdef name="jfxsignjar" classname="com.sun.javafx.tools.ant.FXSignJarTask"
                                    classpathref="maven.plugin.classpath" />
                                <jfxdeploy width="1024" height="768"
                                    outdir="${project.build.directory}/deploy" outfile="${project.build.finalName}"
                                    nativeBundles="all">
                                    <info title="${project.name}" />
                                    <!-- set the main class of your applcation; I had to create a Main.class (class Main extends MyMain) otherwise it will return an error on start-->
                                    <application name="${project.name}" mainClass="TP3.projet_session.App" />
                                    <resources>
                                        <fileset dir="${project.build.directory}" includes="*.jar" />
                                        <fileset dir="${project.build.directory}/dependency"
                                            includes="*.jar" />
                                    </resources>
                                    <!-- set your jvm args-->
                                    <platform javafx="${javafx.version}+">
                                        <jvmarg value="-Xms512m" />
                                        <jvmarg value="-Xmx1024m" />
                                    </platform>
                                </jfxdeploy>

                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ant-javafx</artifactId>
                        <version>${javafx.version}</version>
                        <systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
                        <scope>system</scope>
                    </dependency>
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>javafx</artifactId>
                        <version>${javafx.version}</version>
                        <systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
                        <scope>system</scope>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
        <finalName>Medical-Application</finalName>
    </build>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>javafx</artifactId>
      <version>${javafx.version}</version>
      <systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
      <scope>system</scope>
    </dependency>
      <!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>3.7.2</version>
    </dependency>

  </dependencies>
</project>

I've read that compiling with an IDE and Maven manages the classpath for the runtime too. Is there a way so we can run it properly when we try to open it with a command line?

Any ideas?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

-1

You need to include the JDBC driver in the classpath. When invoking java -jar Medical-Application.jar, the jvm looks in your current directory for the sqlite lib. You will need to do something like

java -cp path/to/sqlite.jar -jar Medical-Application.jar

This way java can find the correct location of the jdbc driver.

riccio
  • 47
  • 9