我知道这一定很简单,但是我花了大约 2 个小时搜索,直到现在我还没有找到任何我能理解的解决方案。
好吧,我可以从 Eclipse 控制台毫无问题地使用我的程序,但是当我尝试从 Windows 命令行运行它时,我从 Hibernate Classes 中得到错误。
从 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 依赖项。我希望有人可以帮助我。谢谢...