Jump to content
We've recently updated our Privacy Statement, available here ×

Scriptlet example


jamiedenman100

Recommended Posts

Hi

I have been trying to get my head around using scriptlets and have managed to get the test report (Sales By Month) working in Jasperserver and (after much flapping about) in iReports.  As I cannot find the source for the test.testScriptlet class I created a simple "Hello World" scriplet and got it working in iReports but when I create the JAR file and upload it to JasperServer I keep getting "Bad version number in .class file" error message.

SCRIPTLET CODE BELOW:

I think it's to do with having to copy jasperreports-3.7.0.jar - unjar it to get iReports to find net.sf.jasperreports.engine.JRDefaultScriptlet??

Does anyone have any simple scriplet source code and details of how to get it to work with both iReports and Jasperserver?  Thanks Jamie

Code:
import java.sql.*;import java.io.InputStream;import java.io.FileInputStream;import net.sf.jasperreports.engine.JRDefaultScriptlet;import java.util.List;public class testMyScriptlet extends JRDefaultScriptlet {  public String message() {	String titlevalue2 = "WE ARE HERE";	return new String(titlevalue2);	  }}
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The "Bad version number in .class file" error is caused by having a jar that is compiled under java 1.6 and trying to run it under java 1.5. (there can be other reasons but this is the most common). Maybe your ireport and jasperserver are installed on different machines and they are using different java versions?

So, see about recompiling the scriptlet jar under java 1.5. Java is backwards compatible, if you compile under 1.5 then this jar will run fine under java 1.6. Also, you can still use java 1.6 to create a 1.5 compatible jar, you can specify a cross-compilation option. Something like: javac -target 1.5

Link to comment
Share on other sites

Thanks for your reply tkavanagh

I tried re-compiling with different version but same result.  So I uninstalled both Jasperserver and iReports and re-installed using the bundled iReports 3.7.0, thinking they'd both have to be using same JAVA but still got the same result.  So went back to the drawing board and found that the bundled version of Jasperserver had its own JAVA folder in it and when I changed the system path to point at this rather than the JDK I'd installed it worked!!

I was wondering why I was having these problems when having the latestest JAVA JDK installed.  Now to try and move on from "HELLO WORLD" to scriptlet that actually does something involving other JARs!!

Thanks again, Jamie 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...