Saw this today and thought I'd drop it here for reference ... a java5 solution to programmatic lookup:
"This class handles looking up service providers on the class path. It implements the Service Provider section of the JAR File Specification<http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider> . The Service Provider programmatic lookup was not specified prior to Java 6 so this interface allows use of the specification prior to Java 6." http://docs.jboss.org/seam/3/solder/latest/api/org/jboss/solder/util/service/ServiceLoader.html On Fri, Nov 25, 2011 at 3:12 AM, jonathan wood <jonathanshaww...@gmail.com>wrote: > Note that the linked second form of newInstance(...) seems to bo 1.6 > specific > > > On Fri, Nov 25, 2011 at 3:06 AM, jonathan wood <jonathanshaww...@gmail.com > > wrote: > >> >> I believe you are experiencing a ServiceLoader in your xerces jar file. >> You can test this by looking for the file >> /META-INF/services/javax.xml.parsers.SAXParserFactory. If it exists, you >> have a few choices.... >> >> Brute force...remove the file from the xerces jar and repackage (relies >> on classpath and a one-off jar...not a good solution). >> >> You can manipulate the load of the "service" implementation by iterating >> over the options... >> >> ServiceLoader<SAXParserFactory> serviceLoader = >> ServiceLoader.load(SAXParserFactory.class); >> serviceLoader.iterator(); >> for (SAXParserFactory spf : serviceLoader) { >> // spf.??? >> } >> >> Directly load the impl you want ... >> SAXParserFactory.html#newInstance(java.lang.String, >> java.lang.ClassLoader)<http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance(java.lang.String,%20java.lang.ClassLoader)> >> >> >> I'd advise reading the javadoc for both forms of newInstance >> >> >> Hope this helps >> >> >> >> On Thu, Nov 24, 2011 at 5:05 AM, Alex Geller <a...@4js.com> wrote: >> >>> Hi, >>> I am not sure if this is a Batik only issue but since I encountered it >>> using >>> Batik I will share the problem and the solution I have found so far. >>> >>> Description of the problem: >>> If you have a program that reads XML files and you add >>> "xerces_2_5_0.jar" to >>> your CLASSPATH on a HP-UX machine (or any other machine that has >>> proprietary >>> XML encodings) then the program may fail with the exception >>> "org.xml.sax.SAXParseException: Invalid encoding name "HP-ROMAN8"". >>> >>> Note that the existence of this jar in the CLASSPATH is sufficient to >>> make >>> this happen. The following test program illustrates the issue (forgive >>> the >>> deprecation warning): >>> >>> import org.xml.sax.InputSource; >>> import javax.xml.parsers.SAXParserFactory; >>> import java.io.StringBufferInputStream; >>> public class EncodingTest >>> { >>> public static void main(String[] args) throws Exception >>> { >>> >>> SAXParserFactory.newInstance().newSAXParser().getXMLReader().parse(new >>> InputSource(new StringBufferInputStream("<?xml version=\"1.0\" >>> encoding=\"HP-ROMAN8\"?> "))); >>> } >>> } >>> >>> Consider the following invocations: >>> Example 1: >>> $(unset CLASSPATH;java -Djaxp.debug=1 EncodingTest) >>> JAXP: find factoryId =javax.xml.parsers.SAXParserFactory >>> JAXP: loaded from fallback value: >>> com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl >>> JAXP: created new instance of class >>> com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using >>> ClassLoader: null >>> $ >>> >>> Example 2: >>> $(export CLASSPATH=.:$BATIKDIR/batik-1.7/lib/xerces_2_5_0.jar;java >>> -Djaxp.debug=1 EncodingTest) >>> JAXP: find factoryId =javax.xml.parsers.SAXParserFactory >>> JAXP: found jar >>> resource=META-INF/services/javax.xml.parsers.SAXParserFactory using >>> ClassLoader: sun.misc.Launcher$AppClassLoader@df6ccd >>> JAXP: found in resource, >>> value=org.apache.xerces.jaxp.SAXParserFactoryImpl >>> JAXP: created new instance of class >>> org.apache.xerces.jaxp.SAXParserFactoryImpl using ClassLoader: >>> sun.misc.Launcher$AppClassLoader@df6ccd >>> [Fatal Error] :1:43: Invalid encoding name "HP-ROMAN8". >>> Exception in thread "main" org.xml.sax.SAXParseException: Invalid >>> encoding >>> name "HP-ROMAN8". >>> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown >>> Source) >>> at EncodingTest.main(EncodingTest.java:9) >>> $ >>> >>> Now, the issue can be fixed by forcing the JVM to use the default >>> factory by >>> settings the property javax.xml.parsers.SAXParserFactory as described in >>> >>> http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance() >>> as follows: >>> >>> Example 3: >>> >>> $(export CLASSPATH=.:$BATIKDIR/batik-1.7/lib/xerces_2_5_0.jar;java >>> >>> -Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl >>> -Djaxp.debug=1 EncodingTest) >>> JAXP: find factoryId =javax.xml.parsers.SAXParserFactory >>> JAXP: found system property, >>> value=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl >>> JAXP: created new instance of class >>> com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using >>> ClassLoader: null >>> $ >>> >>> Questions: >>> 1) Is it necessary to include xerces_2_5_0.jar in the CLASSPATH? >>> 2) If yes, how can I load documents with local encodings and use Batik at >>> the same time. >>> >>> Thanks, >>> Alex >>> >>> ~ >>> >>> -- >>> View this message in context: >>> http://batik.2283329.n4.nabble.com/org-xml-sax-SAXParseException-Invalid-encoding-name-HP-ROMAN8-tp4103307p4103307.html >>> Sent from the Batik - Users mailing list archive at Nabble.com. >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org >>> For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org >>> >>> >> >