Jump to content
We've recently updated our Privacy Statement, available here ×
  • Building Custom Code in Eclipse


    Michael Bielkiewicz
    • Features: JasperReports Server Version: v8, v7, v6, v5 Product: JasperReports® Server

    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.

    project1.gif.08beafbb76ee98cb33ae88f2c184f7b3.gif

    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:

    project2.gif.2604335fc3c389cd8c3dc8f89b2f88bd.gif

    In this screen, select Add Library and choos User Library and hit next.

    project3.gif.b8a7e3d1e0ad45332ff647b30c486f04.gif

    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.

    project4.gif.e528ad094061c8b03affb7bc3b94bc81.gif

     ---

     project5.gif.f4a58e3b838dbbc163d793fadf096a0c.gif

    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. 

    project6.gif.0c8a83f630b759315af1c834ad15805e.gif

     ---

     project7.gif.c8f927815e36a27fadfdd00c36daee81.gif

    Click Apply and Close and ensure your new library is checked and click Finish.

    project8.gif.418e6ffd6c47de1bacb48c56348ec22d.gif

    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.

    project9.gif.e94e618491d7b784ef765851e9b8bcdb.gif

    Select JAR File under the Java folder and click Next.

    project10.gif.a043998d9bbcd7c5c3e01d092c98f438.gif

    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.

    project11.gif.ad91abf0bbe3d069dbb617a2e2955064.gif

    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


    User Feedback

    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 account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...