2013-10-08 139 views
1

我知道它一定很簡單,但我花了大約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來導出。 我希望有人能幫助我。謝謝...

+1

庫類不在類路徑上。 –

回答

3

這意味着您的Hibernate和Mysql環境沒有正確設置。它在eclipse中運行,因爲它會有一些內置的依賴關係。因此,將所需的庫添加到正確的類路徑中,然後嘗試。

+0

這是一個確切的答案! @Patrick爲了增加這一點,一些框架在安裝本身時添加類路徑,而如果它們不需要手動添加。 –

+0

謝謝你,我很抱歉這個愚蠢的問題。我將在稍後檢查課程路徑,然後如果我能解決問題,我會通知您。 –

+0

@PatrickMacedo讓我知道如果你的問題在檢查classpath後解決 – Jhanvi

2

在通過控制檯運行程序時,您在類路徑中缺少所需的jar。您可以在eclipse中檢查所有需要的庫/ jar,在通過控制檯運行時將列表和jar包放入classpath中。

相關問題