收录日期:2019/08/18 17:44:30 时间:2014-03-10 22:25:08 标签:java,web-services,soap,jaxb,jax-rpc

There are identical classes of java WebServices API & IMPL in those packages groups, only package names are different.

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 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.

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