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.(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 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();
}
}
}
}

你可能感兴趣的:(osgi)