我知道它一定很簡單,但我花了大約2個小時在四處搜索,直到現在我還沒有找到任何我能理解的解決方案。代碼在eclipse中工作,但不在命令行中
那麼,我可以使用我的程序沒有任何問題從Eclipse控制檯,但是當我嘗試從Windows命令行運行它時,我從Hibernate類中得到錯誤。
當從Eclipse中運行,我得到這個:
Maven + Hibernate + MySQL
Out 08, 2013 2:13:56 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Out 08, 2013 2:13:56 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.0.Final}
Out 08, 2013 2:13:56 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Out 08, 2013 2:13:56 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Out 08, 2013 2:13:56 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Out 08, 2013 2:13:56 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Out 08, 2013 2:13:56 AM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: emp_geo/entity/Posicao.hbm.xml
Out 08, 2013 2:13:56 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Out 08, 2013 2:13:56 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Out 08, 2013 2:13:56 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Out 08, 2013 2:13:56 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Out 08, 2013 2:13:56 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://54.214.103.119:3306/emp_geo]
Out 08, 2013 2:13:56 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=xxxxx, password=****}
Out 08, 2013 2:13:59 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Out 08, 2013 2:13:59 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Out 08, 2013 2:13:59 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Out 08, 2013 2:13:59 AM org.hibernate.search.Version <clinit>
INFO: HSEARCH000034: Hibernate Search 4.3.0.Alpha1
Out 08, 2013 2:13:59 AM org.hibernate.search.impl.ConfigContext getLuceneMatchVersion
WARN: HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.
當從命令行中運行,這就是我得到:
Maven + Hibernate + MySQL
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
at com.disko.hibernate.persistence.HibernateUtil.configureSessionFactory (HibernateUtil.java:15)
at com.disko.hibernate.persistence.HibernateUtil.getSessionFactory(HibernateUtil.java:23)
at com.disko.hibernate.App.main(App.java:21)
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
我一直在找裏面的Java構建路徑已經,選擇Maven Dependencies來導出。 我希望有人能幫助我。謝謝...
庫類不在類路徑上。 –