views:

33

answers:

1

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?

+1  A: 

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();
Jesper
yes, it's true.I'm using Spring WS which uses e.g. MessageFactory, so then I can pass the MessageFactory.newInstance() or MessageFactory.newInstance("Protocol"), but e.g. Apache CXF does not want to work without an impl of e.g. saaj-impl and some others which are only from com.sun.*
Zilvinas