Senhores,
Boa tarde,
Preciso gerar os PDFs de uma aplicação para .docx também (Atualmente os usuários de a opção de gerar apenas os documentos em PDF). Pensei em usar o docx4j. Mas estou apenas com 1 único erro para prosseguir com os meus testes. Se puderem me ajudar agradeço!!! Muito obrigado a todos mais 1 vez!
Erro:
--------------------------------[ jar ]---------------------------------
--- exec-maven-plugin:1.2.1:exec (default-cli) @ docx4jExample ---
2021-06-18 11:05:24 INFO Context - java.vendor=Oracle Corporation
2021-06-18 11:05:24 INFO Context - java.version=1.8.0_162
2021-06-18 11:05:24 INFO Context - No MOXy JAXB config found; assume not intended..
2021-06-18 11:05:24 INFO NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
2021-06-18 11:05:24 INFO Context - Using Java 6/7 JAXB implementation
2021-06-18 11:05:26 INFO Context - Not using MOXy; using com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
2021-06-18 11:05:26 WARN XmlUtils - Xalan jar missing from classpath; xslt not supported
2021-06-18 11:05:26 WARN ResourceUtils - Couldn't get resource: docx4j.properties
2021-06-18 11:05:26 WARN Docx4jProperties - Couldn't find/read docx4j.properties; docx4j.properties not found via classloader.
2021-06-18 11:05:26 INFO XmlUtils - setProperty com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
2021-06-18 11:05:26 INFO XmlUtils - actual: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
2021-06-18 11:05:26 INFO XmlUtils - setProperty com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
2021-06-18 11:05:26 INFO XmlUtils - actual: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
2021-06-18 11:05:26 INFO ContentTypeManager - Detected WordProcessingML package
2021-06-18 11:05:26 INFO Load3 - Instantiated package of type org.docx4j.openpackaging.packages.WordprocessingMLPackage
2021-06-18 11:05:26 INFO XPathFactoryUtil - xpath implementation: com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl
2021-06-18 11:05:26 INFO Load3 - package read; elapsed time: 2382 ms
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xml/utils/PrefixResolver
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.docx4j.jaxb.NamespacePrefixMapperSunInternal.getPreferredPrefix(NamespacePrefixMapperSunInternal.java:71)
at com.sun.xml.internal.bind.v2.runtime.output.NamespaceContextImpl.declareNsUri(NamespaceContextImpl.java:140)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.startElement(XMLSerializer.java:896)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.startElement(XMLSerializer.java:251)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:325)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:479)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:308)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:130)
at org.docx4j.openpackaging.parts.JaxbXmlPart.marshal(JaxbXmlPart.java:634)
at org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator.createRawXmlPart(FlatOpcXmlCreator.java:217)
at org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator.saveRawXmlPart(FlatOpcXmlCreator.java:182)
at org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator.get(FlatOpcXmlCreator.java:123)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.transform(WordprocessingMLPackage.java:229)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.filter(WordprocessingMLPackage.java:293)
at org.docx4j.model.datastorage.migration.VariablePrepare.prepare(VariablePrepare.java:79)
at docx4jExample.GenerateDocuments.generateDocument(GenerateDocuments.java:58)
at docx4jExample.main.main(main.java:30)
Caused by: java.lang.ClassNotFoundException: org.apache.xml.utils.PrefixResolver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 30 more
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.eti.teste</groupId>
<artifactId>docx4jExample</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>com.j256.simplemagic</groupId>
<artifactId>simplemagic</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>xmlgraphics-commons</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>