I get following exception in LINQ Template: "Error! Can not resolve
method ‘getResourceAsStream’ on type ‘class c.v.s.b.g.DocumentGenerator’ running Spring Boot application
on Java 16 or 17.
On Java 15 it works like expected.
DocumentGenerator class:
public class DocumentGenerator {
public static InputStream getResourceAsStream(String path) throws IOException {
final ClassPathResource classPathResource = new ClassPathResource(path);
return classPathResource.getInputStream();
}
}
Engine execution code:
Document doc = new Document(documentResourceStream);
ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(DocumentGenerator.class);
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS + ReportBuildOptions.INLINE_ERROR_MESSAGES + ReportBuildOptions.REMOVE_EMPTY_PARAGRAPHS);
XmlDataSource dbConstants = new XmlDataSource(getResourceAsStream("doc.xml"));
if (engine.buildReport(doc, dbConstants)) {
LOGGER.info("Document generated successfully!");
} else {
LOGGER.error("Document generation failed! Please check the generated document for inlined error message!");
};
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
doc.save(byteArrayOutputStream, SaveFormat.DOCX);
return byteArrayOutputStream.toByteArray();
Please compress the following resources into ZIP format and attach the .zip file here for testing:
A simplified source Word DOCX document
Aspose.Words generated DOCX file showing the desired output (use Java 15 to produce expected document).
XML file containing the data
Please also create a standalone simplified Java Application (source code without compilation errors) that helps us to reproduce this exception on our end and attach it here for testing. Please do not include Aspose.Words JAR files in it to reduce the file size.
As soon as you get these pieces of information ready, we will then start further investigation into your particular scenario and provide you more information.
zipped Spring Boot application - contains all Java sources, incl. source Word template and subtemplate
resultjava15.docx - result document generated with app running under java 15
resultjava16or17.docx - result document generated with app running under java 16 or 17
How to reproduce :
unzip the file
install maven Maven – Installing Apache Maven
2a. switch to java 11, as the application is written for java 11. Plus maven has to build the project using java 11.
run command: mvn clean install
switch to java 16 or java 17
run command: java -jar target/aspose-java17demo-0.0.1-SNAPSHOT.jar
open browser and run link: http://localhost:8080/doc
Result: you get result doc.docx file with the error downloaded
We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSJAVA-2659. We will further look into the details of this problem and will keep you updated here on the status of linked issue. We apologize for your inconvenience.