java.lang.NoClassDefFoundError: org/apache/log4j/Layout
小弟刚接触hibernate,遇见个问题,望高手解答一下,谢谢
package cn.suqiang.hibernate;
//测试类
public class Test
{
public static void main(String[] args)
{
People people = new People();
people.setId( "4030417 ");
people.setName( "suqiang ");
people.setPassword( "fengbin ");
people.setAge(18);
people.setEmail( "suqiang@sina.com ");
PeopleOperater po = new PeopleOperater();
po.insert(people);
}
}
package cn.suqiang.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class PeopleOperater
{
private Session session = null ;
// 在构造方法之中实例化session对象
public PeopleOperater()
{
// 找到Hibernate配置
Configuration config = new Configuration().configure() ;
// 从配置中取出SessionFactory
SessionFactory factory = config.buildSessionFactory() ;
// 从SessionFactory中取出一个Session
this.session = factory.openSession() ;
}
public void insert(People people)
{
session.save(people);
}
}
Configuration config = new Configuration().configure() ;句
出现异常:
java.lang.
NoClassDefFoundError: org/apache/log4j/Layout
at org.apache.commons.logging.impl.Log4jFactory.getInstance(Log4jFactory.java:140)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:257)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:390)
at org.hibernate.cfg.Configuration. <clinit> (Configuration.java:110)
at cn.suqiang.hibernate.PeopleOperater. <init> (PeopleOperater.java:22)
at cn.suqiang.hibernate.Test.main(Test.java:16)
Exception in thread "main "
什么原因啊?小第初学,不太懂org/apache/log4j/Layout是干什么的?在哪?为什么出现这个情况,谢谢
------解决方案--------------------org/apache/log4j/Layout是用来输出日志的,相当于System.Out
------解决方案--------------------org/apache/log4j/Layout不在路径中,需要加入
------解决方案--------------------到apache网上下一个log4j试一试,这是你的Hibernate要用到的jar,在你的classpath下没找到!
------解决方案--------------------logging-log4j-1.2.14.zip解压啊,解压后目录里有。他logging-log4j-1.2.14.zip包含了文档和.jar等其它东西
------解决方案--------------------log4j在 MyEclipse安装目录\eclipse\plugins\org.apache.jakarta_log4j_版本号\lib目录下
加入到classpath即可
------解决方案--------------------在eclipse 的工程属性的Libraries选项里,把那个jar包加载进去!
------解决方案--------------------觉得可能是少了某个jar包,不一定是少log4j,到底少哪个可就不清楚了。你如果肯定你会导入jar包。那就是还少其他的猜测。
------解决方案--------------------log4j.jar并不是程序跑起来的核心包,你可以把SessionFactory把加载日志的语句屏蔽掉试试