Linux + Eclipse + jdbc = DISASTER

Discussion in 'Plugin Development' started by Visagalis, Mar 2, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Visagalis

    Ok, i was about to make simple plugin, which uses mysql and stuff :) and all went smooth, till i "exported it to jar, and tried to launch server using it."

    my servers throws me this error:
    00:00:54 [INFO] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    then i've noticed that i must SOMEHOW include jdbc-connector.jar in my required libs to my project, but i tried like 100 diffrent ways, and none helped me. If you had such problems and resolved them, please let me know.

    or please share your ideas of how i could solve this problem.

    method which calls this exception is:

    Code:
        private void connect()
        {
            try
            {
                String userName = "user";
                String password = "pass";
                String url = "jdbc:mysql://127.0.0.1:3306/mc";
                Class.forName("com.mysql.jdbc.Driver").newInstance ();
                conn = DriverManager.getConnection (url, userName, password);
                System.out.println ("Database connection established");
            }
            catch (Exception e)
            {
                System.out.println (e.toString()); // this line
            }
        }
     
  2. Offline

    Grum Bukkit Team Member

    -cp path/to/jar.with.com.mysql.jdbc.Driver.jar
     
  3. Offline

    Visagalis

    Grum i can't understand :confused:


    Edit:
    anyway i got answer on IRC, by SquallSeeD31

    i've needed to create MANIFEST.MF file manually somewhere and put:
    Code:
    Manifest-Version: 1.0
    Class-Path: ../lib/mysql-connector-java.jar
    in its content, then when exporting i must select not to generate manifest, but to use mine instead. and finally i need to put mysql-connector-java.jar in Craftbukkit/lib/ dir. that connector can be obtained from here: http://dev.mysql.com/downloads/mirror.php?id=401352
     
  4. Offline

    sunkid

    To expand on Grum's comment, you are getting this error because java, which is running CraftBukkit for you, is not able to find the mysql-connector-java.jar file. In order for it to be able to do so, you need to put that file into the classpath when you start the server or go your route. You can either do so by specifying a classpath when you run java (as Grum suggested) or by putting that jar where java already looks by default (typically the directory you run from and additional system directories).

    I assume, you are planning to package the mysql jar with your own classes. This may or may not be legal and/or wise and a better way would be to instruct users to install the jar themselves by downloading it to the same directory as the craftbukkit jar. This should do it, but unfortunately, some users will still have problems due to a lack of understanding how java works. [​IMG]
     
  5. Offline

    phondeux

    I've never been able to get Eclipse to do that; no matter what I do it ignores me and just throws it's own MANIFEST.MF into the jar. [​IMG]
     
  6. Offline

    Raider

Thread Status:
Not open for further replies.

Share This Page