相关疑难解决方法(0)

离线时无法解析hibernate.cfg.xml

每当我与互联网断开连接时,我都会遇到以下异常:

org.hibernate.HibernateException: Could not parse configuration: com/mashlife/resources/hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
    at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)

Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1532)
    ... 45 more
Run Code Online (Sandbox Code Playgroud)

只有当我离线发生.在解析配置时,hibernate是否尝试读取DTD?这里的根本原因是什么?

这是我的hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/foo</property>
        <property name="connection.username">user</property>
        <property name="connection.password">pass</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

        <!-- Disable the …
Run Code Online (Sandbox Code Playgroud)

java hibernate

19
推荐指数
3
解决办法
4万
查看次数

在相对路径上解析具有DTD架构的XML文件

我有以下java代码:


DocumentBuilder db=DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc=db.parse(new File("/opt/myfile"));

/opt/myfile包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE archive SYSTEM "../../schema/xml/schema.dtd">
...

我收到以下错误:

java.io.FileNotFoundException: /../schema/xml/schema.dtd (No such file or directory)

这是一个大型java框架,它使用其他地方生成的XML文件.我认为相对路径是问题所在.我不认为在JVM启动之前更改cwd是可以接受的(路径来自JVM本身读取的配置文件),并且我没有找到在JVM运行时更改cwd的方法.如何使用适当的DTD解析此XML文件?

java xml dtd

10
推荐指数
2
解决办法
2万
查看次数

参考Java中的本地DTD

我有一些XML,我正在使用Java中的SAX解析器进行解析.它从这个序言开始:

<!DOCTYPE math 
    PUBLIC "-//W3C//DTD MathML 3.0//EN"
           "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd">
Run Code Online (Sandbox Code Playgroud)

如何更改此设置以使用本地DTD?

我想我可以这样做:

<!DOCTYPE math 
    PUBLIC "-//W3C//DTD MathML 3.0//EN"
           "file:///c:/MathML/mathml3.dtd">
Run Code Online (Sandbox Code Playgroud)

不是那样的,但是那样的东西.但是,我需要路径独立于用户的系统.

如何使用具有相对于类路径的路径的本地DTD?

java xml dtd sax

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×3

dtd ×2

xml ×2

hibernate ×1

sax ×1