Loading user data source classes at runtime

JReport allows you to create your report sets using user data source (UDS), user defined objects (UDO), and user defined formulas (UDF). When you publish the report sets using UDS, UDO or UDF to your production environment, JReport requires the UDS, UDO or UDF jars to be in the classpath or part of the EAR bundle. This might be difficult for you. You need to shut down your application and wrap the new UDS, UDO or UDF classes into the WAR or EAR or put them in the classpath of the application server.

The feature Loading User Classes at Runtime can solve this issue. That is, for standalone JReport Enterprise Server, or in your embedded application server calling the Server API, you can control loading the classes at runtime without shutting down your application.

Methods

There are two important methods in the Server API that you need to call to dynamically load your UDS classes:

Usage

Follow the steps below:

  1. Specify a folder location on the machine where JReport Enterprise Server runs to hold all the UDS/UDO/UDF jar files, so that you can specify to load the classes from that folder. When JReport Enterprise Server initializes, you can specify the location in one of the following ways:

    Note: In general, among the above three approaches, the first has the highest priority, and the third has the lowest.

  2. Check the dynamic UDS/UDO/UDF folder any time by calling the method static String jet.server.api.ServerEnv.getDynamicClassDir().

    Usage of the method:

    HttpUtil.getHttpRptServer().getServerEnv().getDynamicClassDir()

    Example:

    System.out.println("Dynamic path"+httpRptServer.getServerEnv().getDynamicClassDir());

    You can get the path's value in your own properties file. You can even copy your UDS/UDO/UDF jar files to the above folders programmatically.

  3. Specify to load classes at runtime by calling the method static void jet.server.api.engine.ReportEngineFactory.loadClasses(java.lang.String path). The parameter path is the dynamic class folder.

    For example:

    ReportEngineFactory.loadClasses(httpRptServer.getServerEnv().getDynamicClassDir());

Notes (technical issues):