我正在尝试使用Hibernate注释运行应用程序。我收到以下异常
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
Exception in thread "main" java.lang.ExceptionInInitializerError
at tapes.test.validation.SessionUtil.<clinit>(SessionUtil.java:17)
at java.lang.Class.initializeClass(libgcj.so.90)
at tapes.test.validation.LuceneSearch.dbFullIndex(LuceneSearch.java:34)
at tapes.test.validation.LuceneSearch.main(LuceneSearch.java:143)
Caused by: java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
at java.lang.Class.initializeClass(libgcj.so.90)
at net.sf.cglib.core.DebuggingClassWriter.toByteArray(DebuggingClassWriter.java:73)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:26)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at java.lang.Class.initializeClass(libgcj.so.90)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at tapes.test.validation.SessionUtil.<clinit>(SessionUtil.java:14)
...3 more
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.util.TraceClassVisitor not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/usr/local/tomcat/webapps/SearchDoctors/Webcontent/WEB-INF/classes/,file:/usr/local/tomcat/webapps/SearchDoctors/WEB-INF/lib/ant-1.6.5.jar,file:/usr/local/tomcat/webapps/SearchDoctors/WEB-INF/lib/ant-antlr-1.6.5.jar,file:/usr/local/tomcat/webapps/SearchDoctors/WEB-INF/lib/ant-junit-1.6.5.jar,file:/usr/local/tomcat/webapps/SearchDoctors/WEB-INF/lib/ant-launcher-.....
这是代码。
public static void dbFullIndex() throws CorruptIndexException, LockObtainFailedException, IOException{
try{
directory = FSDirectory.getDirectory("/home/athreya/luceneindex/docsIndexFile");
//Index of the User Table--> /home/araghu/aditya/indexFile
Session session = SessionUtil.getSessionFactory().getCurrentSession();
if(IndexReader.indexExists(directory)){
writer = new IndexWriter(directory, new StandardAnalyzer(),true);
System.out.println("Index exists");
}
else{
writer = new IndexWriter(directory, new StandardAnalyzer(),true);
System.out.println("Index doesn't Exist");
}
session.beginTransaction();
org.hibernate.Query query = session.createQuery("from Doctors");
java.util.List docList = query.list();
session.getTransaction().commit();
for( int iter=0;iter< docList.size();iter++){
Doctors docs=(Doctors) docList.get(iter);
String pkid=docs.getId()+"";
String indexString= docs.getFirstName()+" "+docs.getMiddleName()+" "+docs.getLastName()+
" "+docs.getAddress()+" "+docs.getCity()+" "+docs.getHospitalNames()+" "+docs.getSpecialization()+" "
+docs.getQualification()+" "+docs.getNatProId();
//String specialString =docs.getSpecialization()+" "+docs.getHospitalNames();
writer.addDocument(createDoc(indexString,pkid));
System.out.println("Name ="+ docs.getFirstName());
// writer.addDocument(createSpDoc(specialString));
}
writer.close();
}catch(Exception e){
e.printStackTrace();
}
}
任何人都可以解释我的问题。我在lib中有cglib jar。我的java_home设置如下--- export JAVA_HOME = / usr / jdk1.6.0_18 /
请帮助我长时间挣扎。
谢谢, 阿迪亚
答案 0 :(得分:1)
如果您的WEB-INF / lib中有JAR,那么它可能是错误的版本。我打开JAR并确保所讨论的类确实包含在内部。
您似乎不依赖于CLASSPATH环境变量。这很好,因为Tomcat完全忽略了它。您的JAR需要位于Web上下文的WEB-INF / lib或server / lib中,以便Tomcat类加载器能够找到它们。
答案 1 :(得分:0)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.util.TraceClassVisitor
您需要在运行时类路径中包含ASM。当您运行Web应用程序时,它需要位于/WEB-INF/lib
。它通常已包含在您从Hibernate获得的下载包中。将其复制到运行时类路径。
答案 2 :(得分:0)
非常感谢大家!问题是Eclipse中的默认版本与JAVA_HOME路径不同。我想这就是问题所在。现在很好。如果还有其他问题,我知道你们在哪里。非常感谢。