I have just attempted to deploy onto Heroku a change to my Java 8 application, which includes an XSL transformation. The deploy fails because the Maven build fails, with the message:

cannot find symbol 
symbol:   method newDefaultInstance()
location: class javax.xml.transform.TransformerFactory

As far as I know, the standard way to do an XSL transformation is to create a TransformerFactory using the above method, then use that to create a Transformer with the XSL stylesheet, then use the Transformer to process the XML document that needs to be transformed. (See https://docs.oracle.com/javase/8/docs/api/javax/xml/transform/package-summary.html)

The code I have written to do this compiles and runs successfully in my local environment, so I don't understand why it doesn't work on Heroku. Is it using a different (non-standard) Java 8 JDK?

Or is there a better way to do what I want?


The method TransformerFactory.newDefaultInstance() was introduced in Java 9; looks as if you are compiling against Java 8 or earlier.

(The method was introduced to enable applications to explicitly invoke the XSLT processor bundled with the JDK, rather than picking up whatever XSLT processor it finds lying around on the classpath, which can easily break the application, because there's no guarantee it will be 100% compatible. In particular, putting Saxon on your classpath can easily break applications that are dependent on working with an XSLT 1.0 processor).

  • Thank you Michael, it was the use of newDefaultInstance() rather than newInstance that I was doing wrong. It worked on my local machine because it is actually a Java 13 JDK. Stupid mistake. Nov 2 '21 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.