xml parser jdk版本切换后出错,解决方法set 应用服务器 jdk/optional java vm arguments:

文章详细介绍了在从JDK 1.4升级到JDK 1.6时,由于XML解析器归属问题导致的编译错误,并提供了三种解决方案:修改jaxp.properties文件、在应用服务器配置中设置、以及在程序中直接设置。重点解决了如何通过调整配置避免使用不兼容的解析器,确保XML解析程序在不同JDK版本间的兼容性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

set  resin jdk/optional java vm arguments:

-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl

 

使用xml解析的程序在jdk1.4中没有问题,在jdk1.6中出现编译错误,原因是因为xerces的归属问题,致使jdk版本升级后产生问题.

最初的xml解析器是sun的Crimson和IBM的Xerces,这两个开源项目都捐给了apache组织,
后来Xerces发展很快,Crimon基本没有人使用。
1.4 版本起,用于XML处理的JavaAPI就已经加入了Java2平台中。利用该API,
可通过一系列标准的Java平台API来处理XML文档。
因此,也就无需另外添加XML处理包了。sun的JDK1.4使用Crimson,IBM的JDK使用Xerces。

因此,SUN的JDK缺省就是去看Crimson的XML实装jar, 所以必须用某种方式告诉他别用你的那个Crimson,而是采用IBM的Xerces。

 

设置方法有三:

1.在JRE/lib/目录下,建立一个jaxp.properties的文件,
    内容如下:
    javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
    javax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
   就可以使用Xerces。
2.或者在应用服务器例如tomcat/resin/weblogic启动的设定当中进行设定
# Add the XML parser jars and set the JAXP factory names
# Xerces parser JAXP setup
CLASSPATH=$CLASSPATH:../lib/xerces.jar
JAXP=-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
JAXP=”$JAXP -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl”

3.在程序中设定,第一次会出现问题,但是之后就会设定成功

System.setProperty(”javax.xml.parsers.DocumentBuilderFactory”,
       “org.apache.xerces.jaxp.DocumentBuilderFactoryImpl”);
System.setProperty(”javax.xml.parsers.SAXParserFactory”,
       “org.apache.xerces.jaxp.SAXParserFactoryImpl”);

C:\Users\小姚\.jdks\openjdk-23.0.2\bin\java.exe -Xmx700m -Djava.awt.headless=true "-Djna.boot.library.path=C:\Program Files\JetBrains\IntelliJ IDEA 2024.3.4.1/lib/jna/amd64" -Djna.nosys=true -Djna.noclasspath=true --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dpreload.project.path=C:/Users/小姚/IdeaProjects/untitled2 -Dpreload.config.path=C:/Users/小姚/AppData/Roaming/JetBrains/IntelliJIdea2024.3/options -Dcompile.parallel=true -Drebuild.on.dependency.change=true -Didea.IntToIntBtree.page.size=32768 -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=-5578464900214876872 -Djps.use.dependency.graph=true -Dfile.encoding=UTF-8 -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2024.3 "-Djps.language.bundle=C:/Program Files/JetBrains/IntelliJ IDEA 2024.3.4.1/plugins/localization-zh/lib/localization-zh.jar" "-Didea.home.path=C:/Program Files/JetBrains/IntelliJ IDEA 2024.3.4.1" -Didea.config.path=C:/Users/小姚/AppData/Roaming/JetBrains/IntelliJIdea2024.3 -Didea.plugins.path=C:/Users/小姚/AppData/Roaming/JetBrains/IntelliJIdea2024.3/plugins -Djps.log.dir=C:/Users/小姚/AppData/Local/JetBrains/IntelliJIdea2024.3/log/build-log "-Djps.fallback.jdk.home=C:/Program Files/JetBrains/IntelliJ IDEA 2024.3.4.1/jbr" -Djps.fallback.jdk.version=21.0.6 -Dio.netty.noUnsafe=true -Djava.io.tmpd
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值