`
- 浏览:
6053 次
-
org.dom4j.DocumentException: file:\E:\work-plugins\console\plugins\power7000.dcp
做osgi应用时,在插件业务中访问资源,报异常。
Nested exception:
java.io.FileNotFoundException: file:\E:\work-plugins\console\plugins\power7000.dcp.protocol.gdwDriver_1.0.0.201701011807.jar\conf\driver.xml (文件名、目录名或卷标语法不正确。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at org.dom4j.io.SAXReader.read(SAXReader.java:243)
at power7000.dcp.protocol.gdwdriver.impl.helper.XmlHelper.buildDocument(XmlHelper.java:55)
at power7000.dcp.protocol.gdwdriver.impl.helper.XmlHelper.buildDecodeRule(XmlHelper.java:106)
at power7000.dcp.protocol.gdwdriver.impl.GdwDriverServiceImpl.decode(GdwDriverServiceImpl.java:35)
at power7000.dcp.framewrok.common.helper.BundleHelper.handleDecReference(BundleHelper.java:165)
at power7000.dcp.framewrok.common.helper.ByteHelper.handleDecode(ByteHelper.java:107)
at power7000.dcp.framewrok.tcp.codec.MessageDecoder.decode(MessageDecoder.java:52)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:227)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:140)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:74)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelRead(DefaultChannelHandlerInvoker.java:138)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:320)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:127)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:794)
at java.lang.Thread.run(Thread.java:745)
解决方案如下:可行,
SAXReader reader = new SAXReader();
Enumeration<URL> e = Activator.context.getBundle().findEntries("/conf/", "driver.xml", true);
if(e != null) {
while(e.hasMoreElements()) {
URL url = e.nextElement();
if(url != null) {
InputStream in;
try {
in = url.openStream();
doc = reader.read(in);
break;
} catch (IOException | DocumentException e1) {
e1.printStackTrace();
}
}
}
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
当我们遇到“java.lang.ClassNotFoundException: org.dom4j.DocumentException”的错误提示时,这通常意味着系统中缺少了DOM4j库,只需将“org.dom4j.jar”添加到项目类路径中即可解决此问题。 DOM4J是基于DOM和SAX...
解决 com.itextpdf.text.DocumentException: Font 'STSongStd-Light' with 'UniGB-UCS2-H' is not recognized. 亲测可用!
【dom4j基础入门文档(SAX,DOM,XPATH)】 dom4j是一个流行的Java库,专门用于处理XML文档。相较于W3C DOM API,dom4j的优势在于它内置了本地XPath支持,使得XML文档的查询和操作更为简便。本文将深入介绍dom4j的...
1. **下载`dom4j`库**:可以从官方网站http://dom4j.org/下载`dom4j`的最新版本,通常包括`dom4j-full.jar`或`dom4j.jar`等文件。 2. **配置ClassPath**:将下载的jar文件添加到项目的ClassPath中。如果是`dom4j-...
import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; public class Dom4JExample { public static void main(String[] args) { try { SAXReader reader = new SAXReader(); Document document...
首先,我们import dom4j的相关类,包括Document、DocumentException、DocumentHelper和Element等。然后,我们使用DocumentHelper.parseText方法来解析XML字符串,并获取根元素。最后,我们可以使用Element对象的方法...
* @throws org.dom4j.DocumentException occurs whenever the build process fails. */ public void parseWithSAX(File aFile) throws DocumentException { SAXReader xmlReader = new SAXReader(); this.doc =...
import org.dom4j.DocumentException; import org.dom4j.DocumentFactory; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class Dom4jDemo { public static void main(String[] args) { try ...
4. **异常处理**: dom4j在源码中广泛使用了异常处理机制,如`DocumentException`和`IOException`,确保在处理XML时能捕获并处理可能出现的问题。 **五、使用示例** 以下是一个简单的dom4j使用示例: ```java import...
import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class Dom4JExample { public static void main(String[] args) { try { SAXReader reader = new ...
import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; ``` 接下来,我们将创建一个`SAXReader`实例,它是DOM4J中的解析器,用于读取XML文件: ```java SAXReader ...
import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; File file = new File("emailTemplateConfig.xml"); SAXReader reader = new SAXReader(); try { Document document = reader.read(file); }...
import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; public class Dom4jExample { public static void main(String[] args) { try { SAXReader reader = new SAXReader(); Document document...
### 使用dom4j读取XML的四种方法 在Java开发中,处理XML文件是一种常见的需求。Dom4j作为一款简洁高效的Java库,被广泛应用于解析、操作XML文档。本文将详细介绍使用dom4j读取XML文件的四种常见方法,并通过示例...
import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; public class ParseXML { public static void main(String[] args) { SAXReader reader = new SAXReader(); try { Document document = ...
import org.dom4j.DocumentException; import org.dom4j.DocumentFactory; import org.dom4j.Element; import java.io.File; public class Dom4jExample { public static void main(String[] args) { try { // ...
import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; // 创建DocumentBuilder SAXReader reader = new SAXReader(); try { // 读取XML文件 Document doc = reader.read(new File("path/to/...
import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class Dom4jExample { public static void main(String[] args) { try { // 创建SAXReader对象 ...
import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; import org.xml.sax.helpers.DefaultHandler; public class Dom4jSaxExample { public static void main(String[] args) { SAXReader ...