Question

I am upgrading my environment from eclipse 3.3.1 and java 1.4 to eclipse 3.4.1 and java 1.5. My unit tests are in jUnit 3.

eclipse java version 1.5.0__17

stand alone env version 1.5.0__12, or 1.5.0-17, both work.

I have a method on a class that writes an XML file to disk. It calls TransformerFactory tf = [javax.xml.transform.]TransformerFactory.newInstance(); When I run the code outside of eclipse it runs fine. When I run the code in jUnit in eclipse I get the stack trace below. The missing class is in the rt.jar of java 1.4 and not in java 5, but shouldn't that be abstracted from me?

How can I make the test pass?

I get the same error when I run the code in eclipse from an application.

java.lang.NoClassDefFoundError: org/apache/xalan/processor/TransformerFactoryImpl
 at weblogic.xml.jaxp.RegistryTransformerFactory.(RegistryTransformerFactory.java:62)
 at weblogic.xml.jaxp.RegistrySAXTransformerFactory.(RegistrySAXTransformerFactory.java:12)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
 at java.lang.Class.newInstance0(Class.java:350)
 at java.lang.Class.newInstance(Class.java:303)
 at javax.xml.transform.FactoryFinder.newInstance(FactoryFinder.java:100)
 at javax.xml.transform.FactoryFinder.findJarServiceProvider(FactoryFinder.java:278)
 at javax.xml.transform.FactoryFinder.find(FactoryFinder.java:185)
 at javax.xml.transform.TransformerFactory.newInstance(TransformerFactory.java:103)
 at com.bellsouth.snt.cnmp.sso.netcool.NetcoolAccessThread.writeXmlFile(NetcoolAccessThread.java:278)
 at com.bellsouth.snt.cnmp.sso.netcool.NetcoolAccessThreadTest.testWriteXmlFile(NetcoolAccessThreadTest.java:83)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at junit.framework.TestCase.runTest(TestCase.java:164)
 at junit.framework.TestCase.runBare(TestCase.java:130)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:120)
 at junit.framework.TestSuite.runTest(TestSuite.java:230)
 at junit.framework.TestSuite.run(TestSuite.java:225)
 at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

update I did some more research in the bowels of the stack trace. The working versions (outside eclipse) are returning an instance of com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl which is the fallback impl class name in javax.xml.transform.TransformerFactory.newInstance()

    public static TransformerFactory newInstance()
        throws TransformerFactoryConfigurationError {
        try {
            return (TransformerFactory) FactoryFinder.find(
            /* The default property name according to the JAXP spec */
            "javax.xml.transform.TransformerFactory",
            /* The fallback implementation class name, XSLTC */
            "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
        } catch (FactoryFinder.ConfigurationError e) {
            throw new TransformerFactoryConfigurationError(
                e.getException(),
                e.getMessage());
        }
    }
Was it helpful?

Solution 2

I added the following line to setup of the unittest

    System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");

I figured out what to do with a bit of RTFM. http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/transform/TransformerFactory.html#newInstance()

OTHER TIPS

You could check if you are running with the same Java version when running in Eclipse as when running outside of it (in Eclipse: Run As -> Run Configuration... -> JRE tab).

Add the Xalan JAR to the classpath.

Also see here if you are using WebLogic. You'll have to put the JAR in shared/lib.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top