Java持久性.jar文件未运行



我已经构建了一个简单的应用程序,它连接了derby(Netbeans)中创建的数据库,该数据库使用java持久性、实体管理器与jTable绑定。问题是,当我在其他系统上运行.jar文件时,它不会执行。有人能告诉我为什么会这样吗?

在其他系统上运行时出错:

C:>java -jar persist.jar
[EL Info]: 2013-01-08 17:06:45.715--ServerSession(4597467)--EclipseLink, version
: Eclipse Persistence Services - 2.3.2.v20111125-r10461
[EL Severe]: 2013-01-08 17:06:48.24--ServerSession(4597467)--Exception [EclipseL
ink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.p
ersistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLNonTransientConnectionException: java.net.Connec
tException : Error connecting to server localhost on port 1527 with message Conn
ection refused: connect.
Error Code: 40000
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: E
xception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r104
61): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLNonTransientConnectionException: java.net.Connec
tException : Error connecting to server localhost on port 1527 with message Conn
ection refused: connect.
Error Code: 40000
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(En
tityManagerSetupImpl.java:517)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.get
DatabaseSession(EntityManagerFactoryDelegate.java:188)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.cre
ateEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createE
ntityManagerImpl(EntityManagerFactoryImpl.java:294)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createE
ntityManager(EntityManagerFactoryImpl.java:272)
    at persist.NewJFrame.initComponents(NewJFrame.java:30)
    at persist.NewJFrame.<init>(NewJFrame.java:17)
    at persist.NewJFrame$1.run(NewJFrame.java:101)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v2
0111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLNonTransientConnectionException: java.net.Connec
tException : Error connecting to server localhost on port 1527 with message Conn
ection refused: connect.
Error Code: 40000
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(Dat
abaseException.java:324)
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(Dat
abaseException.java:319)
    at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConn
ector.java:138)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(
DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAn
dDetectDatasource(DatabaseSessionImpl.java:584)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.log
in(EntityManagerFactoryProvider.java:206)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(En
tityManagerSetupImpl.java:488)
    ... 21 more
Caused by: java.sql.SQLNonTransientConnectionException: java.net.ConnectExceptio
n : Error connecting to server localhost on port 1527 with message Connection re
fused: connect.
    at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unkn
own Source)
    at org.apache.derby.client.am.SqlException.getSQLException(Unknown Sourc
e)
    at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConn
ector.java:98)
    ... 25 more
Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectExcep
tion : Error connecting to server localhost on port 1527 with message Connection
refused: connect.
    at org.apache.derby.client.net.NetAgent.<init>(Unknown Source)
    at org.apache.derby.client.net.NetConnection.newAgent_(Unknown Source)
    at org.apache.derby.client.am.Connection.<init>(Unknown Source)
    at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
    at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
    at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConne
ction(Unknown Source)
    ... 29 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at javax.net.DefaultSocketFactory.createSocket(Unknown Source)
    at org.apache.derby.client.net.OpenSocketAction.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 35 more

看看这个SO问题。似乎是一个类似的问题(即,依赖jar(s)可能不在classpath上)。

编辑
由于您发布了堆栈跟踪,现在很明显您有一些DB连接问题:

java.net.ConnectException : Error connecting to server localhost on port 1527 with messageConnection refused: connect.

你检查过数据库是否启动了吗?在另一个系统上运行正常吗?

检查persistence.xml中的数据库url

<properties>
 <property name="javax.persistence.jdbc.password" value="sa"/>
 <property name="javax.persistence.jdbc.user" value="sa"/>
 <property name="javax.persistence.jdbc.driver" 
                         value="org.apache.derby.jdbc.ClientDriver"/>
 <property name="javax.persistence.jdbc.url" value="jdbc:derby://??:1527/??"/>
</properties>

Netbeans分配默认位置,当你在Netbeans中运行应用程序,你的数据库是创建的。我建议您将url作为创建实体管理器工厂的参数传递,或者将其放在属性文件中并加载它。

java -jar project.jar persistence.properties

相关内容

  • 没有找到相关文章

最新更新