开发者

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.

  • http://mvnrepository.com/artifact/javax.xml
  • http://mvnrepository.com/artifact/com.sun.xml

Which ones should I use in my code? I would prefer NON-com.sun.* as per java conventions, but still my dependencies ( e.g. Spring ) are using implementations from com.sun.* OR I can't find an implementation package in javax.xml

Does anyo开发者_JAVA百科ne 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.

See: Why Developers Should Not Write Programs That Call 'sun' Packages

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. For example, to get a SAX parser you do:

import javax.xml.parsers.*;

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜