简体   繁体   English

WS Libs:com.sun.xml vs javax.xml

[英]WS Libs: com.sun.xml vs javax.xml

There are identical classes of java WebServices API & IMPL in those packages groups, only package names are different. 这些包组中有相同类的java WebServices API和IMPL,只有包名称不同。

Which ones should I use in my code? 我应该在我的代码中使用哪些? I would prefer NON-com.sun.* as per java conventions, but still my dependencies ( eg Spring ) are using implementations from com.sun.* OR I can't find an implementation package in javax.xml 我更喜欢NON-com.sun。*按照java惯例,但我的依赖(例如Spring)仍然使用com.sun的实现。*或者我在javax.xml中找不到实现包

Does anyone have any experience on this? 有没有人有这方面的经验?

Use the javax.xml packages - the com.sun packages are not part of the public Java API and may change between Java versions, or they don't even exist if you use someone else's than Sun's Java implementation. 使用javax.xml包 - com.sun包不是公共Java API的一部分,可能在Java版本之间更改,或者如果您使用其他人而不是Sun的Java实现,它们甚至不存在。

See: Why Developers Should Not Write Programs That Call 'sun' Packages 请参阅: 为什么开发人员不应编写调用“sun”软件包的程序

I don't know what exactly you're trying to do, but you normally do not need to deal with the implementation packages directly. 我不知道你到底想要做什么,但通常你不需要直接处理实现包。 Usually there are factory classes and methods to get an instance of for example an XML parser, and your program does not need to know what implementation is used behind the scenes. 通常有工厂类和方法来获取例如XML解析器的实例,并且您的程序不需要知道幕后使用什么实现。 For example, to get a SAX parser you do: 例如,要获得SAX解析器,您可以:

import javax.xml.parsers.*;

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM