Patrick Macedo
Patrick Macedo

Reputation: 45

code works in eclipse but not in command line

I know it must be something quite simple, but it took me about 2 hours searching around and I didn't find any solution I could understand until now.

Well, I can use my program without any problem from Eclipse console, but when I try to run it from Windows Command Line, I get errors from Hibernate Classes.

When running from Eclipse, I get this:

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.

When running from the Command Line, that's what I get:

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

I've been looking inside Java Build Path already, selecting Maven Dependencies to export. I hope someone could help me with it. Thanks...

Upvotes: 1

Views: 1849

Answers (2)

Jhanvi
Jhanvi

Reputation: 5139

It means that environment for your Hibernate and Mysql is not properly set up. It runs in eclipse, because it would have some inbuilt dependencies. So add the required libraries to the correct classpath and then try.

Upvotes: 3

Juned Ahsan
Juned Ahsan

Reputation: 68715

You are missing the required jars on your classpath while running the program through console. You can check all the required libraries/jar in eclipse, take list and those jars in classpath while running through console.

Upvotes: 2

Related Questions