Creating Custom Code In Eclipse
Frequently it is necessary to create custom Java code or modify base Jaspersoft Java code for certain customizations or to add features to your installation such as preAuth token-based SSO. This article will show you one way to build these custom classes in Eclipse and deploy them to your JasperReports Server instance.
First step is to create a new Java Project in Eclipse. Most default project-creation options are acceptable, however keep in mind that it's best to build your code against the same version of Java that you are running your JasperReports Server under.
Then you need to add the Jaspersoft libraries to your project's build path so you can compile your new/updated classes. Right-click your new project and select Build Path and then Configure Build Path:
In this screen, select Add Library and choos User Library and hit next.
If you do not already have a user library defined for your current version of JasperReports Server, click the User Libraries button and then click the New button to create a new one.
---
Once you've chosen an appropriate name, click Ok, highlight your new library and click Add External Jars. Navigate to your jaspersoft installation directories, and under <tomcatInstall>/lib select all the .jar files and select Open. This adds all the jars to your newly created user library. Re-highlight your library name and click Add External Jars again. This time navigate to your <jasperInstall>/WEB-INF/lib directory and choose all the .jar files there and select Open.
---
Click Apply and Close and ensure your new library is checked and click Finish.
Your library should now show up on your Build Path screen. Click Apply and Close to return to your project.
Develop your code. Once you are ready to create your jar file, right-click on your project or source folder within your project and select Export.
Select JAR File under the Java folder and click Next.
On this screen you can now choose exactly which resources (java classes) you'd like to include in your jar file. Do so and then choose a location to save the JAR file. You can optionally select the "Export Java source files and resources" if you want the uncompiled classes included in your Jar file. Click Next or Finish as the default settings on the next pages are sufficient.
Now you need to simply copy your newly create Jar file to your <jasperInstall>/WEB-INF/lib directory and reboot your server. All files with .jar extensions in this directory get loaded in the JasperReports Server JVM on startup and hence are available to any code that might be calling it. Generally, you will have to reference the custom class you've written in an xml file in your WEB-INF directory or directly from your JRXML file(s) if the code is intended to be used as a helper class/method.
MJB
Recommended Comments
There are no comments to display.
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