Level 3: Application Integration • Chapter 3.1 Pre-compilation Pipelines
การคอมไพล์เทมเพลตรายงานแบบ On-the-fly ณ รันไทม์ (JasperCompileManager.compileReport) บน Production ถือเป็นข้อผิดพลาดร้ายแรงที่สุดในงานสถาปัตยกรรมระดับ Enterprise เพราะสร้างคลาส Evaluator โหลดเข้า JVM Metaspace อย่างต่อเนื่อง ก่อให้เกิด Metaspace OutOfMemoryError และ CPU Spikes 100% การทำ Pre-compilation Pipeline ในขั้นตอน Build ด้วย Maven หรือ Gradle จึงเป็นมาตรฐานบังคับ
| Failure Mode | Impact | Architectural Defense |
|---|---|---|
| Runtime JRXML Compile | Metaspace OOM, Latency Spike | Pre-compile เป็น .jasper ล่วงหน้า 100% |
| Classpath Isolation Leak | ClassNotFoundException ใน CI | กำหนด additionalClasspath ใน Build Plugin |
| Engine Version Drift | InvalidClassException (serialVersionUID) | Rebuild .jasper ทุกรอบการ Release ผ่าน Pipeline |
[CI/CD Build Phase: Maven / Gradle]
src/main/resources/reports/*.jrxml
│ (AST Parsing & Evaluator Generation)
▼
target/classes/reports/*.jasper (Bytecode)
[Production JRE 21 Runtime Container]
InputStream is = getResourceAsStream("*.jasper");
JasperReport report = (JasperReport) JRLoader.loadObject(is);
JasperPrint print = JasperFillManager.fillReport(report, params, ds);
(Zero Metaspace Pollution & Zero Compiler Overhead)
ตรวจสอบและเขียนเทมเพลต JRXML ที่ได้มาตรฐาน Unified Element Model (<element kind="...">) 100% เพื่อเตรียมความพร้อมให้ CI/CD Plugin นำไปคอมไพล์เป็น .jasper โดยไร้ข้อผิดพลาด
| TRANSACTION ID | SETTLEMENT ROUTE | STATUS | AMOUNT |
|---|---|---|---|
| TXN-88392019-E | ACCT-99201-US (CHASE-NY) | SETTLED | $1,250,000.00 |
| TXN-88392020-E | ACCT-44102-GB (BARCLAYS-LDN) | SETTLED | $842,150.00 |
| TXN-88392021-E | ACCT-11029-JP (MUFG-TYO) | SETTLED | $430,900.00 |
| TXN-88392022-E | ACCT-88301-CH (UBS-ZURICH) | SETTLED | $3,100,500.00 |
ทดสอบความเข้าใจเชิงลึกเกี่ยวกับ Build Mechanics, Classloaders, Bytecode, และ Production Pitfalls
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<version>2.13.0</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile-reports</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/reports</sourceDirectory>
<outputDirectory>${project.build.outputDirectory}/reports</outputDirectory>
<additionalClasspath>${project.build.outputDirectory}</additionalClasspath>
<failOnMissingSourceDirectory>true</failOnMissingSourceDirectory>
<stopOnFailing>true</stopOnFailing>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>7.0.3</version>
</dependency>
</dependencies>
</plugin>