Eine hinzugefügte Java-Abhängigkeit tötet meinen alten XML-ManipulationscodeJava

Java-Forum
Anonymous
 Eine hinzugefügte Java-Abhängigkeit tötet meinen alten XML-Manipulationscode

Post by Anonymous »

Es gibt meinen alten Arbeitscode, der eine XML-Datei neu schreibt:

Code: Select all

private static void rewriteXmlDocument(Document document, File xmlFile) throws TransformerException, FileNotFoundException {
File temporaryFile = new File(xmlFile.getParent() + File.separator + "temporary.xml"); // write to a temporary file
DOMSource source = new DOMSource(document);
TransformerFactory transformerFactory = TransformerFactory.newInstance();

Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

if(temporaryFile.exists()) temporaryFile.delete(); // there is a trash

StreamResult result = new StreamResult(new FileOutputStream(temporaryFile));
transformer.transform(source, result);

xmlFile.delete(); // write succeeded, now we can delete the old
temporaryFile.renameTo(xmlFile); // rename temporary to old name
}
Wenn ich diese beiden Abhängigkeiten zu pom.xml hinzufüge (und etwas Code zum Suchen in einer docx), erhalte ich eine Ausnahme aus der Zeile „transformerFactory.newTransformer()“.

Code: Select all

    
org.docx4j
docx4j
6.1.2


org.glassfish.jaxb
jaxb-runtime
2.3.1

Ausnahme ist:

Code: Select all

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xml/serializer/TreeWalker
at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:818)
at AnanlyzeEmails/AnalyzeEmailsApplication.AnalyzeEmailsApp.rewriteXmlDocument(AnalyzeEmailsApp.java:170)
Wie kann ich meinen alten XML-Manipulationscode neben jaxb verwenden?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post