Hello,

I'm new to maven and Java 5 and I just started a project using Maven
2.  So far everything has been great except for the following issue. 
I'm currently having a problem getting a particular unit test to run
successfully.  I'm using java 1.5.0_04 and was trying to validate some
XML against a schema.  I'm compiling the schema.

My code looks like this:

        final SAXParserFactory spf = SAXParserFactory.newInstance();
        System.out.println(spf.getClass().getName());
        spf.setSchema(schema);
        final SAXParser saxParser = spf.newSAXParser();
        saxParser.parse(new InputSource(new StringReader(xml)), new
FailingHandler(xml));

I got this error:
java.lang.UnsupportedOperationException: This parser does not support
specification "null" version "null"
        at 
javax.xml.parsers.SAXParserFactory.setSchema(SAXParserFactory.java:361)
on the "spf.setSchema(schema);" line

It seems to be because when maven runs the unit test, it picks up the
SAXParserFactory "org.apache.xerces.jaxp.SAXParserFactoryImpl"; when
run from eclipse it picks up
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl" which
is coming from the Java5 libraries.  Running maven with the -X option,
I can see there are numerous Xerces libraries being put in the
classpath, for example:
[DEBUG] /home/tim/.m2/repository/xerces/xercesImpl/2.6.2/xercesImpl-2.6.2.jar
[DEBUG] 
/home/tim/.m2/repository/xerces/xmlParserAPIs/2.6.2/xmlParserAPIs-2.6.2.jar
[DEBUG] /home/tim/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar
[DEBUG] /home/tim/.m2/repository/xerces/xerces/2.0.2/xerces-2.0.2.jar

So I added <forkMode>once</forkMode> to the surefire plugin.  However,
this caused my unit tests to fail earlier with the following
exception:

java.lang.LinkageError: Class javax/xml/transform/Source violates
loader constraints
        at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:489)

Does anyone have any suggestions on how to resolve this issue?  Is
forking the unit test the correct thing to do?  Do I need to add the
Java5 libraries to the classpath ahead of the others?

Update: So I found a workaround when <forkMode> is not set - by
manually telling jaxp which parser factory to use:
        System.setProperty("javax.xml.parsers.SAXParserFactory",
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
This seems like a bit of a kludge though - I don't like specifying
internal Java classes.  However, things still fail when I use the
Cobertura plugin to do code coverage, since that seems to force a
fork.  So I guess I still need to figure out how to get my unit tests
to run with <forkMode>once</forkMode>.

Info:
echo $JAVA_HOME
/opt/apps/jdk1.5.0_04

java -version
java version "1.5.0_04"

mvn -version
Maven version: 2.0.1

Any help would be greatly appreciated,
Thanks,

Tim

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to