We are using BIRT on our project which currently has dependencies on Javax.
We need to deploy on Wildfly 27 and migrate to Jakarta but BIRT viewer has a dependency on AXIS2 which is not yet migrated to Jakarta.
We have agreed on removing the BIRT viewer module to bypass this issue.
However, the team is having little success in achieving that due to unfamiliarity with the technologies used.
Could we get clear steps on how to remove the viewer module and have it compile successfully?
Intellij IDE is being used instead of Eclipse.
Tried removing the entire module but compilation is failing. Errors are hard to diagnose because intellij code highlighting isn't working due to BIRT being developed in Eclipse.
Method without BIRT Viewer:
WEB-INF
├── lib
├── reports
│ ├── Students2.rptdesign <-- report1
│ ├── hello_world.rptdesign <-- report2 (copy from birt.war)
│ └── hello_world_chart.rptdesign <-- report3 (copy from birt.war)
└── web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" id="WebApp_ID" version="6.0">
<display-name>helloweb6</display-name>
<!-- report1 -->
<servlet>
<servlet-name>Report1Servlet</servlet-name>
<servlet-class>com.example.ReportServlet</servlet-class>
<init-param>
<param-name>reportFile</param-name>
<param-value>/WEB-INF/reports/Students2.rptdesign</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Report1Servlet</servlet-name>
<url-pattern>/report1</url-pattern>
</servlet-mapping>
<!-- report2 -->
<servlet>
<servlet-name>Report2Servlet</servlet-name>
<servlet-class>com.example.ReportServlet</servlet-class>
<init-param>
<param-name>reportFile</param-name>
<param-value>/WEB-INF/reports/hello_world.rptdesign</param-value>
</init-param>
<init-param>
<param-name>paramString</param-name>
<param-value>my+parameter</param-value>
</init-param>
<init-param>
<param-name>paramInteger</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>paramList</param-name>
<param-value>2</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Report2Servlet</servlet-name>
<url-pattern>/report2</url-pattern>
</servlet-mapping>
<!-- report3 -->
<servlet>
<servlet-name>Report3Servlet</servlet-name>
<servlet-class>com.example.ReportServlet</servlet-class>
<init-param>
<param-name>reportFile</param-name>
<param-value>/WEB-INF/reports/hello_world_chart.rptdesign</param-value>
</init-param>
<init-param>
<param-name>paramCust</param-name>
<param-value>130</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Report3Servlet</servlet-name>
<url-pattern>/report3</url-pattern>
</servlet-mapping>
</web-app>
package com.example;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.*;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
public class ReportServlet extends HttpServlet {
private IReportEngine birtEngine;
@Override
public void init() throws ServletException {
super.init();
EngineConfig config = new EngineConfig();
try {
Platform.startup(config);
} catch (BirtException e) {
throw new RuntimeException(e);
}
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
birtEngine = factory.createReportEngine(config);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String reportTypeDefult = "html";
String reportType = request.getParameter("reportType");
//html , pdf
if (reportType == null || reportType.isEmpty()) {
reportType = reportTypeDefult;
}
String reportFile = getServletConfig().getInitParameter("reportFile");
try {
IReportRunnable design = birtEngine.openReportDesign(getServletContext().getRealPath(reportFile));
IRunAndRenderTask task = birtEngine.createRunAndRenderTask(design);
if (getServletName().equals("Report2Servlet")) {
// Get default parameters from web.xml
String paramString = getServletConfig().getInitParameter("paramString");
// If parameters are passed in the URL query, the default values are overwritten.
String paramStringFromRequest = request.getParameter("paramString");
if (paramStringFromRequest != null && !paramStringFromRequest.isEmpty()) {
paramString = paramStringFromRequest;
}
if (paramString == null || paramString.isEmpty()) {
throw new ServletException("Required parameter 'paramString' is not set.");
}
task.setParameterValue("paramString", paramString);
// Get default parameters from web.xml
String paramInteger = getServletConfig().getInitParameter("paramInteger");
// If parameters are passed in the URL query, the default values are overwritten.
String paramIntegerFromRequest = request.getParameter("paramInteger");
if (paramIntegerFromRequest != null && !paramIntegerFromRequest.isEmpty()) {
paramInteger = paramIntegerFromRequest;
}
if (paramInteger == null || paramInteger.isEmpty()) {
throw new ServletException("Required parameter 'paramInteger' is not set.");
}
// Only For Report 2 - Setting Report Parameters
Integer paramIntegerValue = Integer.valueOf(paramInteger);
task.setParameterValue("paramInteger", paramIntegerValue);
// Get default parameters from web.xml
String paramList = getServletConfig().getInitParameter("paramList");
// If parameters are passed in the URL query, the default values are overwritten.
String paramListFromRequest = request.getParameter("paramList");
if (paramListFromRequest != null && !paramListFromRequest.isEmpty()) {
paramList = paramListFromRequest;
}
if (paramList == null || paramList.isEmpty()) {
throw new ServletException("Required parameter 'paramList' is not set.");
}
// Only For Report 2 - Setting Report Parameters
System.out.println("paramList = " + paramList);
Integer paramListValue = Integer.valueOf(paramList);
System.out.println("paramListValue = " + paramListValue);
task.setParameterValue("paramList", paramListValue);
}
if (getServletName().equals("Report3Servlet")) {
// Get default parameters from web.xml
String paramCust = getServletConfig().getInitParameter("paramCust");
// If parameters are passed in the URL query, the default values are overwritten.
String paramCustFromRequest = request.getParameter("paramCust");
if (paramCustFromRequest != null && !paramCustFromRequest.isEmpty()) {
paramCust = paramCustFromRequest;
}
if (paramCust == null || paramCust.isEmpty()) {
throw new ServletException("Required parameter 'paramCust' is not set.");
}
// Only For Report 3 - Setting Report Parameters
BigDecimal paramCustValue = new BigDecimal(paramCust);
task.setParameterValue("paramCust", paramCustValue);
}
if (reportType.equals("html")) {
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
options.setOutputStream(response.getOutputStream());
response.setContentType("text/html");
task.setRenderOption(options);
}
if (reportType.equals("pdf")) {
// Configuring PDF output options
PDFRenderOption options = new PDFRenderOption();
options.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline; filename=report.pdf");
// Set the PDF output stream as the response output stream
OutputStream out = response.getOutputStream();
options.setOutputStream(out);
task.setRenderOption(options);
}
task.run();
task.close();
} catch (Exception e) {
throw new ServletException("Error generating report", e);
}
}
@Override
public void destroy() {
birtEngine.destroy();
Platform.shutdown();
super.destroy();
}
}
put it into apache-tomcat-10.1.31/webapps/hello
http://localhost:8080/hello/report1
http://localhost:8080/hello/report1?reportType=pdf
http://localhost:8080/hello/report3
Note: Use html view to display, but the pictures and charts of the report are not displayed normally.
http://localhost:8080/hello/report3?reportType=pdf
Note: Use pdf view to display, the pictures and charts of the report are displayed normally.
Java Code: To display a BIRT report without using BIRT Viewer, all you need is to develop a ReportServlet and use IReportEngine birtEngine.
Config File : In addition, set the url and start parameters of the ReportServlet corresponding report in web.xml.
Report File: BIRT report files are placed under the WEB-INF/reports
directory in the WAR.