therrick_1 Posted August 25, 2015 Share Posted August 25, 2015 Created public java class using Eclipse that has a public static method getHello() that returns a String. Created jar file and added as external jar to Jaspersoft Studio report Java Build Path. Set report properties Scriptlet Class to com.jss.SayHello. Created Scriptlet in report and set Class to fully qualified package class as com.jss.SayHello where SayHello is the name of my class. That automatically created a Parameter called Scriptlet_1_SCRIPTLET. I tried to set the parameter Scriptlet_1_SCRIPTLET properties to class of com.jss.SayHello, but it won't let me. It keeps reverting back to net.sf.jasperreports.engine.JRDefaultScriptlet. I put the parameter scriptlet on my report and set the expression to $P{Scriptlet_1_SCRIPTLET].getHello(). When I run the report, I get a compile error that reads "The method getHello() is undefined for the type JRDefaultScriptlet. My Java code and jrxml code is below, any ideas how to fix this:Java code:package com.jss;import net.sf.jasperreports.engine.JRDefaultScriptlet;public class SayHello extends JRDefaultScriptlet { public static String getHello(){String str = "My Scriptlet Hello";return str;} public static void main(String[] args) {}}jrxml code:<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 --><!-- 2015-08-25T09:45:22 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="JSSJava1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" scriptletClass="com.jss.SayHello" uuid="3ef02621-d7e5-4a11-8b8d-9b1b3182cc8b"><property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/><scriptlet name="Scriptlet_1" class="com.jss.SayHello"/><queryString><![CDATA[]]></queryString><background><band splitType="Stretch"/></background><title><band height="79" splitType="Stretch"/></title><pageHeader><band height="35" splitType="Stretch"/></pageHeader><columnHeader><band height="61" splitType="Stretch"/></columnHeader><detail><band height="125" splitType="Stretch"><textField><reportElement x="278" y="57" width="100" height="30" uuid="b378a8e1-f235-4d45-aa71-8fd86b201824"/><textFieldExpression><![CDATA[$P{Scriptlet_1_SCRIPTLET}.getHello()]]></textFieldExpression></textField></band></detail><columnFooter><band height="45" splitType="Stretch"/></columnFooter><pageFooter><band height="54" splitType="Stretch"/></pageFooter><summary><band height="42" splitType="Stretch"/></summary></jasperReport> Link to comment Share on other sites More sharing options...
therrick_1 Posted August 25, 2015 Author Share Posted August 25, 2015 UPDATE: After closing and re-opening the report, now the Scriptlet_1_SCRIPTLET parameter is set as a class of com.jss.SayHello. So that is progress I guess. However, now I get the error "java.lang.ClassNotFoundException: com.jss.SayHello". I've added the jar to the Java Build Path Library and also put the .class and .jar files in the bin folder and added that as a Source and added those files to the same folder as the .jrxml. I've added the .jar and .class files in 3 different locations for Jaspersoft to find them, but why can't it? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now