Compiling Java Program

  • Last update:February 21, 2025
  • Overview

    When you need secondary development for FineReport through Java class code to implement certain functions, it is usually necessary to compile Java files to generate Class files. Class files are required in applications such as program data sources, program reports, custom functions, custom background export, and custom printing. So, what preparations are needed for compiling Java files during second development? This document will introduce details.

    Preparing the Compilation Environment

    Project Preparation

    Before compiling the program, you need to create a Java project environment and prepare a Java editor (for example, Eclipse or IntelliJ IDEA). If there is no existing Java project environment, you can create a Java project through the editor (for example, the Ideal editor), as shown in the following figure.

    iconNote:
    When you create a project, the dependent JDK version should not be too high (JDK 1.8 is sufficient).

    1.png

    Importing JAR Packages

    Before compiling the program, you need to import some necessary JAR packages into the project, which is mainly divided into two categories: the FineReport project JAR package and the third-party JAR package required for compiling the program. Among them, the FineReport project JAR package must be imported. The third-party JAR package can be added according to the actual scenario requirements. It does not need to be added if there are no relevant requirements.

    FineReport Project JAR Package

    The FineReport project JAR package that need to be imported includes:

    • All packages under your report project %FR_HOME%/lib directory

    • All packages under the %FR_HOME%/server/lib directory

    • All packages under the %FR_Home%/webapps/webroot/WEB-INF/lib directory

    In addition, JDK's tools.jar needs to be imported.

    Use the Idea editor to import the above necessary packages for creating a project JavaIdea, as shown in the following figure.

    2.png

    Importing the third-party JAR Package

    If you need to import third-party JAR packages, follow the steps below. If you don't need to import, ignore the steps.

    Two main ways are available to import the third-party JAR package.

    1. After downloading the third-party JAR package, place it under the %FR_HOME%\webapps\webroot\WEB-INF\lib directory, which is the same directory as the directory of fine-decision-10.0.jar provided by FineReport. Import the third-party JAR package together with the FineReport project JAR package.

    2. Download and place the third-party package under a custom directory, and then import the package. Use the Idea editor to import the third-party JAR package slf4j-simple-1.7.25 into the JavaIdea project, as shown in the following figure.

    3.png

    Compiling a Java File

    After preparing the compilation environment, you can write and compile a Java file.

    Writing a Java File

    Create a Java file, and write Java codes in the editor. Use the Idea editor to create and write the custom function StringImage, as shown in the following figure.

     4.png

    Compiling a Java File

    After completing a Java file, compile it in the compiler, and no error is reported. After successful compilation, a Class file will be generated in the corresponding project.

    After the custom function StringImage is successfully compiled, the StringImage.class file will be generated in the corresponding project's compilation directory, as shown in the following figure.

    5.png

    Attachment List


    Theme: Secondary Development
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    9s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy