0

Before down voting my question and say that it's a possible duplicate of another question I want to clear out that I looking for a solution for like 5 hours. I have read all the stackoverflow question related to ClassNotFoundException: com.mysql.cj.jdbc.Driver and none of them fix my issue. As far as I know this simply means that I am missing the mysql connector/j library and I double even triple checked and the library is there included in the project and everything is fine with it. I've been searching over the web for a solution and someone suggested modifying 'C:\xampp\mysql\bin\my.ini file' disabling/commenting out 'skip-networking' and 'skip-federated' and enable/uncomment bind-address="127.0.0.1" . In my file 'skip-federated' and 'skip-networking' was disabled/commented out by default so I had to just enable/uncomment bind-address="127.0.0.1", but it still doesn't work an I doubt it's something with the xampp, but then what it could be?

Stack trace of the error

    java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at com.game.server.model.dao.MySQL.JDBCUtil.<clinit>(Unknown Source)
        at com.game.server.launch.LaunchServer.main(Unknown Source)
Exception in thread "main" java.lang.ExceptionInInitializerError
        at com.game.server.launch.LaunchServer.main(Unknown Source)
Caused by: java.lang.RuntimeException: Unable to load mysql driver.
        at com.game.server.model.dao.MySQL.JDBCUtil.<clinit>(Unknown Source)
        ... 1 more

.classpath file of the project (REPO_VAR is eclipse variable that points to the /lib/ dir of the project)

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry exported="true" kind="var" path="REPO_VAR/junit.jar"/>
    <classpathentry exported="true" kind="var" path="REPO_VAR/log4j-1.2.17.jar"/>
    <classpathentry kind="src" path="test"/>
    <classpathentry combineaccessrules="false" kind="src" path="/server-core"/>
    <classpathentry kind="var" path="REPO_VAR/mysql-connector-java-8.0.15.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

The project is build via ant so here's the compilation part of build.xml

<target name="build" depends="compile">
    <jar basedir="${classes.dir}" destfile="${dist.dir}/${project.name}.jar">
        <manifest>
            <attribute name="Class-Path" value="log4j-1.2.17.jar server-core.jar" />
            <attribute name="Main-Class" value="com.game.server.launch.LaunchServer"/>
        </manifest>
    </jar>
</target>

The even funny thing is that the project runs well on Eclipse via right clicking the project > Run As > Java Program, so I am totally confused out there.

Jakub Moz
  • 127
  • 10
  • So it's just that: Eclipse knows about mysql-connetor, but your server doesn't! So you have to deploy that connector to your server as well (whatever you are using as server...) – Gyro Gearless Feb 07 '19 at 10:24
  • What server are you using for deploying your Java project? – Nika Narushvili Feb 07 '19 at 10:29
  • Changing your 'my.ini' won't fix issues with the driver being absent on the classpath. – Mark Rotteveel Feb 07 '19 at 10:40
  • It's a server - client game and well the connector is already deployed to the server and I know that because I was able to run the server back in 2015 without any issues. – Jakub Moz Feb 07 '19 at 10:41
  • @MarkRotteveel as I already mentioned I am aware that my.ini wont solve the issue so how does this answers my question exactly? – Jakub Moz Feb 07 '19 at 10:42
  • Given the error, the driver is not on the runtime classpath. Given you don't provide any hint on how you are running your application, we can't give you any other tip than: fix your classpath. This is covered by the duplicate. Specifically point 2 in [this answer](https://stackoverflow.com/a/2840358/466862). Note that the `.classpath` file only defines the classpath for the project within Eclipse. It doesn't define the classpath when you run your application. – Mark Rotteveel Feb 07 '19 at 10:43
  • It's an ant build and the Class-Path is set from the build.xml look here: https://pastebin.com/tDAEZyEA I have updated my question added the full build.xml file contents. – Jakub Moz Feb 07 '19 at 11:25
  • Fixed it by adding mysql-connector-java-8.0.15.jar to the Class-Path attribute in the ant build.xml file lol I guess it happens when you haven't slept for like 48 hours. Thank you for your help @MarkRotteveel it pointed me to the right direction. – Jakub Moz Feb 07 '19 at 11:33
  • You're welcome! – Mark Rotteveel Feb 07 '19 at 12:24

0 Answers0