java.lang.ClassNotFoundException:org.dom4j.DocumentException [英] java.lang.ClassNotFoundException: org.dom4j.DocumentException

查看:197
本文介绍了java.lang.ClassNotFoundException:org.dom4j.DocumentException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些代码来学习hibernate。它抛出下面的错误。我如何找出问题所在并加以解决? dom4j听起来像是一个XML问题。 hibernate.cfg.xml有问题吗?

 线程main中的异常java.lang.NoClassDefFoundError:org / dom4j / DocumentException 
at com.examscam.model.User.persist(User.java:45)
at com.examscam.model.User.main(User.java:57)
导致:java .lang.ClassNotFoundException:org.dom4j.DocumentException在java.net.URLClassLoader上
$ 1.run(未知源)$ b $在java.net.URLClassLoader $ 1.run(未知源)
在java .security.AccessController.doPrivileged(本地方法)$ b $在java.net.URLClassLoader.findClass(未知源)
在java.lang.ClassLoader.loadClass(未知源)
在sun.misc .Launcher $ AppClassLoader.loadClass(Unknown Source)$ b $ at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
$ b

(为什么eclipse没有显示这个2more的东西?)

代码 -

  package com.examscam.model; 

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;


@实体
公共类用户{

私人长ID;
私人字符串密码;

@Id
@GeneratedValue

public Long getId(){
return id;

}

public void setId(Long id){

Class c1 = User.class;
this.id = id;

}

public String getPassword(){
return password;
}

public void setPassword(String password){
this.password = password;


public static void persist(){
$ b $ * / $
*包含连接数据库所需的所有信息以及$ b $来自JPA注释类的b *信息,也就是这个类。
* /
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(User.class);
config.configure();

SchemaExport schemaExport = new SchemaExport(config);
schemaExport.create(true,true);



$ b public static void main(String [] args){

persist();



$ b

XML文件 -

 <?xml version ='1.0'encoding ='UTF-8'?> 

<!Doctype hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate构型-3.0.dtd>

< hibernate-configuration>
< session-factory>

< property name =connection.url>
jdbc:mysql:// localhost / examscam
< / property>

< property name =connection.username>
root
< / property>

密码
< / property>

< property name =connection.driver_class>
com.mysql.jdbc.Driver
< / property>

< property name =dialect>
org.hibernate.dialect.MySQLDialect
< / property>

< property name =transaction.factory_class>
org.hibernate.transaction.JDBCTransactionFactory
< / property>

< property name =current_session_context_class>
线程
< / property>

<! - 这会显示我们所有的SQL语句 - >

< property name =hibernate.show_sql>
true
< / property>

<! - 我们现在不使用任何映射文件 - >

< / session-factory>
< / hibernate-configuration>

更新

修正了上述错误之后,出现了一个新问题 -



我正在用eclipse编写代码。我添加了代码所需的所有可能的jar,并且我的代码仍然无法运行。为什么当我已经添加sl4fj(
slf4j-api-1.5.8.jar)来构建路径时,发生此错误 java.lang.ClassNotFoundException:org.slf4j.impl.StaticLoggerBinder



错误 -

  SLF4J:无法加载类org。 slf4j.impl.StaticLoggerBinder。 
SLF4J:有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder。
线程main中的异常java.lang.NoClassDefFoundError:org / slf4j
/ impl / StaticLoggerBinder
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
在org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java :269)
在org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
在org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
在org.hibernate。 cfg.Configuration。< clinit>(Configuration.java:152)
at com.examscam.model.User.persist(User.java:45)
at com.examscam.model.User.main (User.java:57)
导致:java.lang.ClassNotFoundException:org.slf4j.impl.StaticLoggerBinder $ b $ java.net.URLClassLoader $ 1.run(未知源)
在java .net.URLClassLoader $ 1.run(未知源)$ java.util.AccessController.doPrivileged(Native方法)
在java.net.URLClassLoad上
er.findClass(未知源代码)$ java.util.ClassLoader.loadClass(未知源代码)
sun.misc.Launcher
$ java.lang。$ AppClassLoader.loadClass(未知源代码)
。 ClassLoader.loadClass(Unknown Source)
... 9 more


解决方案 div>

确保dom4j.jar位于类路径中。



2分钟之后你说的是什么。



当你看到'... 2 more'时,这意味着由'exception by'异常的其余行与父异常的那一行的其余行相同。


I made some code to learn hibernate. It is throwing the error below. How do I find out what the problem is and fix it ? dom4j sounds like an XML problem. hibernate.cfg.xml is the problem ?

Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at com.examscam.model.User.persist(User.java:45)
at com.examscam.model.User.main(User.java:57)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
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)
... 2 more

(why is eclipse not showing this "2more" thing ?)

Code -

package com.examscam.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;


@Entity
public class User {

private Long id;
private String password;

@Id
@GeneratedValue

public Long getId(){
    return id;

}

public void setId(Long id){

    Class c1 = User.class;
    this.id = id;

}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public static void persist(){

    /* 
     * Contains all the info needed to connect to database, along with
     * info from your JPA annotated class, ie this class. 
    */
    AnnotationConfiguration config = new AnnotationConfiguration();
    config.addAnnotatedClass(User.class);
    config.configure();

    SchemaExport schemaExport = new SchemaExport(config);
    schemaExport.create(true, true);

}


public static void main(String[]args){

    persist();

}

}

XML file -

<?xml version = '1.0' encoding='UTF-8' ?>

<!Doctype hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>

<property name = "connection.url">
jdbc:mysql://localhost/examscam
</property>

<property name = "connection.username">
root
</property>

<property name = "connection.password">
password
</property>

<property name = "connection.driver_class">
com.mysql.jdbc.Driver
</property>

<property name = "dialect">
org.hibernate.dialect.MySQLDialect
</property>

<property name = "transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>

<property name = "current_session_context_class">
thread
</property>

<!-- this will show us all the SQL statements-->

<property name = "hibernate.show_sql">
true
</property>

<!-- We dont use any mapping files as of now-->

</session-factory>
</hibernate-configuration>

UPDATE

After fixing the above errors, there is a new problem -

I am making code with eclipse. I added all the possible jars needed for the code and my code is still not working. Why is this error java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder occurring when i already added sl4fj ( slf4j-api-1.5.8.jar) to build path ?

The error -

  SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j   
  /impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
at com.examscam.model.User.persist(User.java:45)
at com.examscam.model.User.main(User.java:57)
   Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
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)
... 9 more

解决方案

Make sure dom4j.jar is in the classpath.

What you are saying by 2more.

When you see '...2 more', that means that the remaining lines of the 'caused by' exception are identical to the remaining lines from that point on of the parent exception.

这篇关于java.lang.ClassNotFoundException:org.dom4j.DocumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆