forked from LogBlock/LogBlock
Added auto downloader for the mysql connector
Moved mysql connector to lib/
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path: ../mysql-connector-java-bin.jar
|
||||
Class-Path: ../lib/mysql-connector-java-bin.jar
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.DriverManager;
|
||||
@@ -44,6 +46,8 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
|
||||
import de.diddiz.util.Download;
|
||||
|
||||
public class LogBlock extends JavaPlugin
|
||||
{
|
||||
static Logger log;
|
||||
@@ -64,6 +68,11 @@ public class LogBlock extends JavaPlugin
|
||||
log.warning("[LogBlock] Permissions plugin not found. Using default permissions.");
|
||||
}
|
||||
}
|
||||
File file = new File("lib/mysql-connector-java-bin.jar");
|
||||
if (!file.exists()) {
|
||||
log.info("[LogBlock] Downloading mysql-connector-java-bin.jar ...");
|
||||
Download.download(new URL("http://diddiz.insane-architects.net/download/mysql-connector-java-bin.jar"), file);
|
||||
}
|
||||
new JDCConnectionDriver(config.dbDriver, config.dbUrl, config.dbUsername, config.dbPassword);
|
||||
Connection conn = getConnection();
|
||||
conn.close();
|
||||
|
28
src/de/diddiz/util/Download.java
Normal file
28
src/de/diddiz/util/Download.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package de.diddiz.util;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class Download
|
||||
{
|
||||
public static void download(URL u, File file) throws Exception {
|
||||
if (!file.getParentFile().exists())
|
||||
file.getParentFile().mkdir();
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
InputStream in = u.openStream();
|
||||
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buffer)) >= 0) {
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user