Jump to content
Changes to the Jaspersoft community edition download ×

Scriptlet help needed


mhbashar1

Recommended Posts

I made a report-TestScriptlet.jrxml .In Scriptlet expression editor(iReport 2.0.2) my code is-

Code:
import net.sf.jasperreports.engine.*;
public class TestScriptlet extends it.businesslogic.ireport.IReportScriptlet {
/** Creates a new instance of JRIreportDefaultScriptlet */
public TestScriptlet() {

}
public String hello(){ return "HELLO WORLD" }
}

Then I selected "use internal scriptlet" in report property.Then I added the folder(in Options>classpath)where this Scriptlet file(TestScriptlet.java) and TestScriptlet.jrxml is created.Then in a textfield expression I wrote this-"

$P{REPORT_SCRIPTLET}.hello()" but I got the following error-

 

net.sf.jasperreports.engine.JRException: Error compiling report java source files : D:Documents and SettingsTonuMy DocumentsMyProjectReportDemoTestScriptletScriptlet.java

....

Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main

Can anubody tell me wher is the problem.How does the name of my Scriptlet uses TestScriptletScriptlet.java when I gave it TestScriptlet in Scriptlet editor?

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Check the Compiler tab from the Options => Settings menu option.

 

I haven't had any problems with the compiler combobox set to "JasperReports default".

 

I changed it to "Java Compiler" and got the same error as you when trying to compile a report.

 

Best Regards,

Mike

Link to comment
Share on other sites

Brother I also tried with both java compiler and jasperReports default but it didn't work.One more amazing thing is if I open TextScriptlet.jrxml file after compiling the errors says-

net.sf.jasperreports.engine.JRException: Error compiling report java source files : D:Documents and SettingsTonuMy DocumentsMyProjectReportDemoTestScriptletScriptlet.java but I named the scriptlet- TestScriptlet in Scriptlet expression editor as my code above in earlier post.Where is the problem?

Link to comment
Share on other sites

Ok. I just tested creating a scriptlet within IReport and changing the name of the class.

 

It took the name I entered but the class name is incorrect in the .jrxml file.

 

Do this:

 

1. Go to Edit => XML Source.

 

2. Look for the "scriptletClass" attribute in the "jasperreport" element. It should be right below the DOCTYPE element.

 

3. Make sure the class name matches the class name you created. If not then change it and save the file. Then reload the report in IReport.

 

 

Best Regards,

Mike

Link to comment
Share on other sites

3. Make sure the class name matches the class name you created. If not then change it and save the file. Then reload the report in IReport.

Brother I also had the same problem as u had.But when I change the name,save it and reload the report,amazingly after reloading the report, the class name isn't changed.It goes back to the earlier name.I tried several times but I can't change the name.IS it a bug?

Link to comment
Share on other sites

Ok. I've found the only way I can compile the scriptlets from within IReport is to put the "tools.jar" file from a JDK install into the IReports "lib" folder.

 

I've successfully compiled the report and scriptlet after doing the above.

 

I find it much easier to develop the scriptlet in an IDE (like Eclipse) and then place the compiled class in the report folder.

 

Best Regards,

Mike

Link to comment
Share on other sites

I've found the only way I can compile the scriptlets from within IReport is to put the "tools.jar" file from a JDK install into the IReports "lib" folder.

I also did the same thing but the problem is- it can't name scriptlet class as I put in the scriptlet editor.This is what i did-

1.Copy and paste of "tools.jar" from jdk ins. to IReports "lib" folder.

2.Make a report and save it as Test.jrxml.

3.Going to Edit>scriptlet editor,I just change the name into "Test" in both class and constructor and save it.

4.Compile it and I got the following error-

Code:
Compiling scriptlet source file... D:Documents and SettingsTonuMy DocumentsMyProjectReportDemoTestScriptlet.java
Errors compiling D:Documents and SettingsTonuMy DocumentsMyProjectReportDemoTestScriptlet.java.
D:Documents and SettingsTonuMy DocumentsMyProjectReportDemoTestScriptlet.java:4: class Test is public, should be declared in a file named Test.java public class Test extends it.businesslogic.ireport.IReportScriptlet {

I noticed that in my report folder there is file created named-

TestScriptlet.java.Whatever name I gave my scriplet class in scriptlet editor,I get a java file in report folder adding the word-"Scriptlet" with the name I put in scriptlet editor.

What is the problem.I also get "scriptletClass="TestScriptlet" in Edit>XML source file.If I change it to "Test" only and save it and reload the report and again going to this file I get the same name-"scriptletClass="TestScriptlet" .ITS GEETING ON MY NERVE NOW.Brother can u pls help me.

One more thing -can I just compile the report anywhere else and put that compiled file in the report folder,will it work?

Link to comment
Share on other sites

Yes you can compile the Scriptlet class outside of IReport and place the compiled .class file in the report directory.

 

But make sure to place it in the correct folder structure if you specify a package name for the class.

 

If you had the following package:

 

net.something.scriptlet

 

Then the compiled class needs to be put in the folder "scriptlet" which is in the folder "something" which is in the folder "net" which will go in your report folder.

 

Also make sure to specify the package name when adding the scriptlet class value.

So if I had a scriptlet class called "MyScriptlet" that was part of the package "net.something.scriptlet" then for the scriptlet class value it would be "net.something.scriptlet.MyScriptlet"

 

Hope that makes sense.

 

Best Regards,

Mike

Link to comment
Share on other sites

  • 4 months later...

Any idea why we have to restart iReport each time we make some changes in scriptlets?

 

For example, make a scriptlet that uses System.out.println("Hello"), use it in your report, run the report and "Hello" will get displayed.

 

Then change "Hello" to "HelloWorld", save your scriptlet

and run your report again, it will still display "Hello"

 

Close iReport and re-open, then re-open your report and run it again, now "HelloWorld" gets displayed!

 

It happens when I use internal scriptlet support and external (building in Eclipse and packaging in a JAR)

Same problem with iReport 2.0.5 and 3.0.0.

 

Anybody knows the fix to this?

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...