Skip to content

Instantly share code, notes, and snippets.

@huxendupsel
Last active December 1, 2016 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huxendupsel/47f60cf3aa3a06b9fb6e72cf2a5c4200 to your computer and use it in GitHub Desktop.
Save huxendupsel/47f60cf3aa3a06b9fb6e72cf2a5c4200 to your computer and use it in GitHub Desktop.
jasperreport compile report over jre leads to exception

Jasperreport compile report over JRE leads to exception

to compile a report via

JasperCompileManager.compileReportToStream(design, os);

you have to provide some kind of compile mechanism. On default the javac of the jdk is used to compile the jrxml to jasper file. So if you're not using jdk but jre instead the code will not work. It will produce exceptions like this:

net.sf.jasperreports.engine.JRException: Error compiling report java source files :C:\Workspace\ABOVU-Client\file_1479896387177_924178.java 
	at net.sf.jasperreports.engine.design.JRJavacCompiler.compileClasses(JRJavacCompiler.java:106)
	at net.sf.jasperreports.engine.design.JRAbstractClassCompiler.compileUnits(JRAbstractClassCompiler.java:77)
	at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:201)
	at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:354)
	at net.sf.jasperreports.engine.JasperCompileManager.compileToStream(JasperCompileManager.java:323)
	at net.sf.jasperreports.engine.JasperCompileManager.compileReportToStream(JasperCompileManager.java:596)
	... local project call stack is dismissed
Caused by: java.io.IOException: Cannot run program "javac": CreateProcess error=2, Das System kann die angegebene Datei nicht finden
	at java.lang.ProcessBuilder.start(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at net.sf.jasperreports.engine.design.JRJavacCompiler.compileClasses(JRJavacCompiler.java:75)
	... 80 more
Caused by: java.io.IOException: CreateProcess error=2, Das System kann die angegebene Datei nicht finden
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
	... 84 more

If you're not able to change the jvm to jdk you have do provide a special jasper-compiler-jdt.jar to the classpath. This jar includs the eclipse jdt that is used to compile the jrxml. I'm not sure if this is a good workaround, because it's not clear who has build this jar. How long it will work regarding usage of newer jdk/jasper versions.

Approach: Use the jdk - or not forcing the clients to change their settings we can swap the code to the server that runs on jdk.

http://www.java2s.com/Code/Jar/j/Downloadjaspercompilerjdtjar.htm https://stackoverflow.com/questions/1642338/how-does-eclipse-compile-classes-with-only-a-jre -> http://stackoverflow.com/a/1658072 -> hint to use eclipses jdt to compile reports

Tags: jasperreports, javac, jdk, jre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment