1.最近在做java爬虫,使用的是webmagic框架,为了使用xpath2.0的语法引入了webmagic-saxon的依赖,导致出现报错:
java.lang.RuntimeException: XPathFactory#newInstance() failed to.....Illegal config
2.找到报错的代码是webmagic-saxon引入的saxon-he中的配置文件报错
<dependency> | |
<groupId>net.sf.saxon</groupId> | |
<artifactId>Saxon-HE</artifactId> | |
<version>9.5.1-1</version> | |
</dependency> |
google了很长时间终于找到答案
由于这个版本的saxon-he (9.5.1)中配置文件的格式不被jdk8接收。
JDK 6和JDK 7接受了非法复合格式;;JDK 8不再接受这种格式。
而我使用的正式jdk1.8
4.解决方案
使用saxon-he的最新版本
就我使用webmagic-saxon而言,首先在webmagic-saxon中去除Saxon-HE,然后再添加Saxon-HE最新版本的依赖
<!-- 支持xpath2.0语法 --> <dependency> <groupId>us.codecraft</groupId> <artifactId>webmagic-saxon</artifactId> <version>0.6.1</version> <exclusions> <exclusion> <groupId>net.sf.saxon</groupId> <artifactId>Saxon-HE</artifactId> </exclusion> </exclusions> </dependency> <!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE --> <dependency> <groupId>net.sf.saxon</groupId> <artifactId>Saxon-HE</artifactId> <version>9.7.0-15</version> </dependency>
这个网站可以搜dependency: http://mvnrepository.com/artifact/org.apache.httpcomponents