Java程序在Netbeans中运行良好,但当从构建的JAR运行时,它不起作用
我现在完全是java的noob,我所要做的就是将MySQL日志添加到Minecraft服务器的java代理中 当程序在NetBeans中运行时,程序运行得非常好,没有任何错误。但是,当构建jar并从jar运行程序时,当登录到Minecraft服务器时,会抛出以下错误: SQLNestedException出错:无法为连接URL“JDBC:mysql://localhost:3306/userips@org.apache.commons.dbcp.BasicDataSource:1452 基本上,它应该做的是记录用户的IP、用户名、登录时间和日期 我正在使用NetBeansIDE7.2.1并使用Maven构建jar来处理所有依赖项 我使用maven将commons-dbcp-1.4.jar、mysql-connector-java-5.1.22.jar和commons-pool-1.5.4.jar导入到依赖项中,它们在jar文件中 以下是建立连接的类:Java程序在Netbeans中运行良好,但当从构建的JAR运行时,它不起作用,java,mysql,netbeans,jdbc,netbeans-7.2,Java,Mysql,Netbeans,Jdbc,Netbeans 7.2,我现在完全是java的noob,我所要做的就是将MySQL日志添加到Minecraft服务器的java代理中 当程序在NetBeans中运行时,程序运行得非常好,没有任何错误。但是,当构建jar并从jar运行程序时,当登录到Minecraft服务器时,会抛出以下错误: SQLNestedException出错:无法为连接URL“JDBC:mysql://localhost:3306/userips@org.apache.commons.dbcp.BasicDataSource:1452 基本上,
import java.sql.Connection;
import java.sql.SQLException;
import org.apache.commons.dbcp.BasicDataSource;
public final class ConnectionPooler {
public static final Configuration config = new Configuration();
private static final BasicDataSource dataSource = new BasicDataSource();
static {
config.load();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl(config.sql_url);
dataSource.setUsername(config.sql_user);
dataSource.setPassword(config.sql_pass);
dataSource.setInitialSize(5);
dataSource.setMaxActive(30);
}
public static Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
}
下面是执行mysql查询和所有操作的类:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public class IPLogger {
public boolean logip(String player, String ipp) throws SQLException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
Calendar now = Calendar.getInstance();
TimeZone timeZone1 = now.getTimeZone();
String timeZone = timeZone1.getDisplayName();
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
Date date1 = new Date();
Date date2 = new Date();
String date;
String time;
date = dateFormat.format(date1);
time = timeFormat.format(date2);
String SQL_EXIST = "INSERT INTO `proxyips` (`username`, `ip`,`date`,`time`) VALUES ('"+player+"', '"+ipp+"','"+date+"','"+time+" "+timeZone+"')";
try{
connection = ConnectionPooler.getConnection();
statement = connection.prepareStatement(SQL_EXIST);
statement.executeUpdate();
} finally {
if (resultSet != null) {
try { resultSet.close(); } catch (SQLException ignore) {ignore.printStackTrace(); }
}
if (statement != null) {
try { statement.close(); } catch (SQLException ignore) {ignore.printStackTrace(); }
}
if (connection != null) {
try { connection.close(); } catch (SQLException ignore) {ignore.printStackTrace(); }
}
}
return true;
}
}
以下是pom.xml,以防我在构建或类似操作时出现一些错误:
<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>net.md-5</groupId>
<artifactId>BungeeCordKC</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCordKC</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.properties</exclude>
<exclude>**/*.SF</exclude>
<exclude>**/*.DSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Main-Class>${main.class}</Main-Class>
<Implementation-Version>${describe}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<build.number>unknown</build.number>
<main.class>net.md_5.bungee.BungeeCord</main.class>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.11.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk15on</artifactId>
<version>1.47</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.22</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<artifactId>commons-pool</artifactId>
<groupId>commons-pool</groupId>
<type>jar</type>
<version>1.5.4</version>
</dependency>
</dependencies>
</project>
4.0.0
net.md-5
蹦极
1.0-快照
罐子
蹦极
http://maven.apache.org
org.apache.maven.plugins
maven编译器插件
2.3.2
1.7
1.7
假的
org.apache.maven.plugins
maven阴影插件
2
*:*
**/*.爪哇
**/*.物业
**/*.SF
**/*.DSA
包裹
阴凉处
org.apache.maven.plugins
maven jar插件
2.4
${main.class}
${descripe}
UTF-8
未知的
net.md_5.bungee.BungeeCord
朱尼特
朱尼特
3.8.1
测试
org.yaml
毒蛇
1.11
org.projectlombok
龙目
0.11.4
番石榴
番石榴
13.0.1
com.google.code.findbugs
注释
2.0.1
org.bouncycastle
bcprov-ext-jdk15on
1.47
mysql
mysql连接器java
5.1.22
罐子
编译
公共dbcp
公共dbcp
1.4
共用池
共用池
罐子
1.5.4
如果有人知道问题出在哪里,或者如果您对我如何设置我的环境有任何疑问,请让我知道
编辑:这是我将catch语句添加到try块时的完整堆栈跟踪
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '
com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql://localhost.com:3306/use
rips'
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(Basic
DataSource.java:1452)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
rce.java:1371)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
.java:1044)
at net.md_5.bungee.ConnectionPooler.getConnection(ConnectionPooler.java:
30)
at net.md_5.bungee.IPLogger.logip(IPLogger.java:44)
at net.md_5.bungee.InitialHandler.run(InitialHandler.java:77)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at com.mysql.jdbc.Util.stackTraceToString(Util.java:355)
at com.mysql.jdbc.Util.<clinit>(Util.java:120)
at com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.jav
a:764)
at com.mysql.jdbc.NonRegisteringDriver.acceptsURL(NonRegisteringDriver.j
ava:265)
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(Basic
DataSource.java:1437)
... 11 more
Caused by: java.lang.RuntimeException: Can't load resource bundle due to underly
ing exception java.util.MissingResourceException: Can't find bundle for base nam
e com.mysql.jdbc.LocalizedErrorMessages, locale en_US
at com.mysql.jdbc.Messages.<clinit>(Messages.java:61)
... 17 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name c
om.mysql.jdbc.LocalizedErrorMessages, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source
)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at com.mysql.jdbc.Messages.<clinit>(Messages.java:59)
... 17 more
org.apache.commons.dbcp.SQLNestedException:无法创建类的JDBC驱动程序'
com.mysql.jdbc.Driver'for connect URL'jdbc:mysql://localhost.com:3306/use
裂口
位于org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(基本
java:1452)
位于org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
rce.java:1371)
位于org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
.java:1044)
在net.md_5.bungee.ConnectionPooler.getConnection(ConnectionPooler.java:
30)
net.md_5.bungee.IPLogger.logip(IPLogger.java:44)
net.md_5.bungee.InitialHandler.run(InitialHandler.java:77)
位于java.util.concurrent.Executors$RunnableAdapter.call(未知源)
位于java.util.concurrent.FutureTask$Sync.innerRun(未知源)
位于java.util.concurrent.FutureTask.run(未知源)
位于java.util.concurrent.ThreadPoolExecutor.runWorker(未知源)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(未知源)
位于java.lang.Thread.run(未知源)
原因:java.lang.ExceptionInInitializeError
位于com.mysql.jdbc.Util.stackTraceToString(Util.java:355)
位于com.mysql.jdbc.Util。(Util.java:120)
位于com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.jav
a:764)
位于com.mysql.jdbc.NonRegisteringDriver.acceptsURL(NonRegisteringDriver.j
艾娃:265)
位于java.sql.DriverManager.getDriver(未知源)
位于org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(基本
DataSource.java:1437)
... 还有11个
原因:java.lang.RuntimeException:无法加载资源包,原因是参考底图
ing异常java.util.MissingResourceException:找不到基本nam的捆绑包
e com.mysql.jdbc.LocalizedErrorMessages,locale en_US
在com.mysql.jdbc.Messages上。(Messages.java:61)
... 还有17个
原因:java.util.MissingResourceException:找不到基名称c的捆绑包
om.mysql.jdbc.LocalizedErrorMessages,locale en_US
位于java.util.ResourceBundle.throwMissingResourceException(未知源
)
位于java.util.ResourceBundle.getBundleImpl(未知源代码
Caused by: java.lang.RuntimeException: Can't load resource bundle due to underly
ing exception java.util.MissingResourceException: Can't find bundle for base nam
e com.mysql.jdbc.LocalizedErrorMessages, locale en_US
at com.mysql.jdbc.Messages.<clinit>(Messages.java:61)
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.properties</exclude>
<exclude>**/*.SF</exclude>
<exclude>**/*.DSA</exclude>
</excludes>
</filter>
</filters>