where does bukkit include sqlite driver

Discussion in 'Plugin Development' started by crolemol, Sep 17, 2014.

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

    crolemol

    Hey,
    I know that bukkit implements the sqlite and mysql driver. I want to include the h2 driver in my plugin because I want to run a h2 database. So to do that I would like to know where bukkit does include those drivers. or how I can include them
     
  2. Offline

    mythbusterma

    crolemol

    A simple search of the JDocs shows where they are. Just use them? What's the question?
     
  3. Offline

    crolemol

    mythbusterma
    Did already search for it on sqlite and mysql and databases but didn't find anything.
    the problem: I'm setting up a h2 database but when I run it, it says :"no suitable driver found". Did already google that. I need to register the h2 driver to the DriverManger class. but I don't know how I need to do that
     
  4. Offline

    mythbusterma

    crolemol

    Are you sure you're using h2 correctly? Also Bukkit loads both MySQL and SQLite, you can initialize it by opening a jdbc connection like:

    Code:java
    1. DriverManager.getConnection(
    2. "jdbc:mysql://" + uri + ":" + port + "/" + databaseName
    3. + "?user=" + user + "&password=" + password);


    Where the variable names are what they say they are.
     
  5. Offline

    fireblast709

    crolemol add the H2 jar to your classpath (with a path that the server jar will be able to find), make sure that the H2 jar is there, and invoke
    Code:
    Class.forName("org.h2.Driver")
     
    mythbusterma likes this.
  6. Offline

    crolemol

    fireblast709
    I did read that but is it just adding it to the Java dependencies or do I need to do that manually. And if I have to do it manually how do I have to do it
    mythbusterma
    I do know that but when I do that it just give me an error. No suitable driver found.
     
  7. Offline

    ZachBora

    CB includes in their jar the Sqlite and Mysql (which increased the jar by like 5mb), I think he wants to do include the H2 driver in his plugin jar?
     
  8. Offline

    fireblast709

    crolemol Since H2 is not added to the CraftBukkit jar, you would need to make sure that the Class-Path entry points to the H2 jar (and the server must be able to find it). A general suggestion would be:
    • add "../lib/H2.jar" to your Class-Path
    • Create the folder <server root>/lib/ and add H2.jar
     
  9. Offline

    crolemol

  10. Offline

    fireblast709

    crolemol I used to do it manually (open the built jar, get manifest.MF, edit it manually), but I'm sure there are way better options depending on how you build your jar (Maven, IDE)
     
  11. Offline

    crolemol

    fireblast709
    I dont know how that does work. I did read the page you said but don't understand it. I would like to install the driver. Could you please give me an example of how i register this driver.
     
  12. Offline

    fireblast709

    crolemol First off, which IDE are you using? (In the case you use Maven to build your plugin, tell me)
     
  13. Offline

    crolemol

  14. Offline

    fireblast709

  15. Offline

    crolemol

    fireblast709
    I understand this a little bit but how would I use this. can I just use the classes from the jar?
     
  16. Offline

    fireblast709

    crolemol basically you would add the <plugin> to the
    Code:
    <build>
        <plugins>
            <!-- here you can add plugins. I bet there are already plugins there
                    so just append one at the end -->
        </plugins>
    </build>
    and set the <Class-Path> to "../lib/H2.jar"

    note: this means that it will look for the H2 lib in the specified path. This happens to be <server root>/lib/H2.jar, assuming that your plugin is located at <server root>/plugins/<your plugin's file name>.jar
    note 2: the mainClass is not required since your plugin doesn't run on itself - instead it will be loaded from Bukkit
     
  17. Offline

    mythbusterma

    crolemol

    My prompt to you is: You don't know how to use H2, why do you need to use it? Someone who understood why they need it would likely know how to use it. MySQL is some of the most powerful SQL server software in the world, and it's already included. What features, SPECIFICALLY, do you NEED that the already included MySQL driver does not support?
     
  18. Offline

    fireblast709

    mythbusterma flatfile databases. Why not SQLite? No clue.
     
  19. Offline

    mythbusterma

  20. Offline

    crolemol

    mythbusterma
    I know how to use H2 I did use it before but not in java and the driver is just missing...
    fireblast709
    sqlite hasn't that many features.(auto increment and ...) which is really required for my plugin because it is really big
     
  21. Offline

    werter318

  22. Offline

    crolemol

    werter318
    what are you trying to explain. that auto increment uses extra CPU?

    fireblast709
    It doesn't work I did do what you said but I doesn't work.
    Code:
    <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>me.crolemol</groupId>
        <artifactId>coc</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>ClashofClans</name>
        <description>coc plugin</description>
        <repositories>
            <repository>
                <id>bukkit-repo</id>
                <url>http://repo.bukkit.org/content/groups/public/</url>
            </repository>
        </repositories>
     
        <dependencies>
            <dependency>
                <groupId>org.bukkit</groupId>
                <artifactId>bukkit</artifactId>
                <version>1.7.9-R0.2</version>
            </dependency>
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>1.4.181</version>
            </dependency>
        </dependencies>
     
        <build>
     
            <finalName>ClashofClans</finalName>
            <sourceDirectory>src/main/java</sourceDirectory>
            <resources>
                <resource>
                    <targetPath>.</targetPath>
                    <filtering>true</filtering>
                    <directory>${basedir}/src/main/resources/</directory>
                    <includes>
                    </includes>
                </resource>
            </resources>
     
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <target>1.7</target>
                        <source>1.7</source>
                    </configuration>
                </plugin>
                <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    <addClasspath>true</addClasspath>
                </manifest>
                <manifestEntries>
                    <Class-Path>/plugins/ClashofClans/lib/h2-latest.jar</Class-Path>
                </manifestEntries>
            </archive>
        </configuration>
    </plugin>
            </plugins>
        </build>
    </project>
    and the part for reaching the class
    Code:java
    1. try {
    2. Class.forName("org.h2.Driver");
    3. return true;
    4. error("H2 driver class missing: " + e.getMessage() + ".");
    5. return false;
    6. }

    and the error :

    H2 driver class missing: org.h2.Driver.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  23. Offline

    mythbusterma

    crolemol

    So you ABSOLUTELY 100% NEED a flatfile database, you cannot, under any circumstances, use MySQL? The reason I'm saying this is because you're are unnecessarily bloating your software, to use a system, which, in many cases, is slower. Consider MySQL more throughly, and develop a case as to why you can't use it, and before you say "I've never used it before," the Java interface for H2 and MySQL is almost indistinguishable due to the JDBC. Also, what is your case against SQLite? It does, in fact, support AUTOINCREMENT, the only feature I could think that you would need is column deletion, which you probably don't anyway, so try again.

    As for why that's not working, you didn't shade the plugin at all, merely said that it depends on it, which the default behavior is not to export it with the plugin. Use Maven shade: http://maven.apache.org/plugins/maven-shade-plugin/
     
  24. Offline

    fireblast709

    crolemol open your jar, check META-INF/manifest.mf. Does 'Class-Path' contain the path you added? If so, then I would like to note that your current path would point to <server root>/plugins/plugins/ClashofClans/lib/h2-latest.jar
     
  25. Offline

    crolemol

    mythbusterma
    I did use it before but not in java. thats why it sounds confusing.What is the difference between h2 and sqlite?
     
  26. Offline

    mythbusterma

    crolemol

    One's included in Bukkit, the other isn't. Also, SQLite is used much more often, and is better supported.
     
Thread Status:
Not open for further replies.

Share This Page