Can we create JasperReports without Maven

installation

Windows users

Unzip the distribution archive into a directory of your choice, for example:

Add the directory

to your user or system search path.

or just use setup.exe

Linux users

Unzip the distribution archive into a directory of your choice, for example:

Add the directory

to your user or system search path.

Call JasperStarter

If you added the bin directory to the search path, just enter the following

to call up the program.

If not, you can enter an absolute path. On Linux:

/ opt / jasperstarter / bin / jasperstarter

and under Windows:

C: \ App \ jasperstarter \ bin \ jasperstarter.exe

if you followed the example in the Installation section.

If you have problems with the binary file or the shell script or want to transfer special options to the Java VM, you can also start the program directly:

$ java -jar /opt/jasperstarter/lib/jasperstarter.jar

or

$ java -cp /opt/jasperstarter/lib/jasperstarter.jar de.cenote.jasperstarter.App

Concepts

JasperReport files

JasperReports knows three types of files:

  • The report definition file myreport.jrxml

    This is an xml file that defines the report. They can be handwritten, but usually you will use one of the beautiful GUI tools to create them.

  • The compiled report file myreport.jasper

    This file is the result when you have a .jrxml Compile file.

  • The filled report file myreport.jrprint

    This file results from a called report. The data that is called up via the specified data source is inserted into the compiled report and the result can be saved as a .jrprint File to be saved.

Stages of processing

There are three stages in processing a report:

  • compile creates a .jasper file
  • to fill can optionally be in a .jrprint File to be saved
  • view, print or export in one or more of the supported export formats.

JasperStarter can do all of these steps in one call.

JasperStarter commands and options

JasperStarter has some global options and commands. Each command can have its own options.

You get an overview when you use jasperstarter -H call, which shows you the global options and the available commands.

$ jasperstarter -h usage: jasperstarter [-h] [--locale ] [-v] [-V] ... optional arguments: -h, --help show this help message and exit - locale set locale with two-letter ISO-639 code or a combination of ISO-639 and ISO-3166 like de_DE -v, --verbose display additional messages -V, --version display version information and exit commands: < cmd> type -h to get help on command compile (cp) compile reports process (pr) view, print or export an existing report list_printers (printers, lpr) lists available printers list_parameters (params, lpa) list parameters from a given report

Each command has its own help, which you can access by calling -h receive.

The command compile (cp)

With the command compilep you can compile a single report or all reports in a directory. cp is an alias for compile.

$ jasperstarter cp -h usage: jasperstarter compile [-h] [-o ] optional arguments: -h, --help show this help message and exit options: input file (.jrxml) or directory -o directory or basename of outputfile (s)

The command process (pr)

The command pr (process) is required to process a single report. This can mean compiling, displaying, printing or exporting. pr is an alias for process.

$ jasperstarter pr -h usage: jasperstarter process [-h] -f [ ...] [-o ] [-w] [-a []] [-P < param> [ ...] view, print, pdf, rtf, xls, xlsMeta, xlsx, docx, odt, ods, pptx, csv, csvMeta, html, xhtml, xml, jrprint input file (. jrxml | .jasper | .jrprint) -o directory or basename of outputfile (s), use '-' for stdout compile options: -w, --write-jasper write .jasper file to imput dir if jrxml is processed fill options: -a [] ask for report parameters. Filter: a, ae, u, ue, p, pe (see usage) -P [ ...] report parameter: name = value [...] -r [] path to report resource dir or jar file. If is not given the input directory is used. datasource options: -t datasource type: none, csv, xml, json, jsonql, mysql, postgres, oracle, generic (jdbc) -H database host -u database user -p database password -n database name --db-sid oracle sid --db-port database port --db-driver jdbc driver class name for use with type: generic --db -url jdbc url without user, passwd with type: generic --jdbc-dir directory where jdbc driver jars are located. Defaults to ./jdbc --data-file input file for file based datasource, use '-' for stdin --csv-first-row first row contains column headers --csv-columns Comma separated list of column names --csv-record-del CSV Record Delimiter - defaults to line.separator --csv-field-del CSV Field Delimiter - defaults to "," --csv-charset CSV charset - defaults to "utf-8" --xml-xpath XPath for XML Datasource --json-query JSON query string for JSON Datasource --jsonql-query JSONQL query string for JSONQL Datasource output options : -N name of printer -d show print dialog when printing -s set internal report / document name when printing -c number of copies. Defaults to 1 --out-field-del Export CSV (Metadata) Field Delimiter - defaults to "," --out-charset Export CSV (Metadata) Charset - defaults to "utf- 8"

The command list_printers (printers,lpr)

The command list_printers has no options. It lists all available printers on your system which you can use with the option -N of the command process can use. printers, lpr are aliases for list_printers.

The command list_parameters (params,lpa)

The command list_parameters lists all user-defined parameters of a given report. params, lpa are aliases for list_parameters.

$ jasperstarter params -h usage: jasperstarter list_parameters [-h] optional arguments: -h, --help show this help message and exit options: input file (.jrxml) or (.jasper)

The columns have the following meanings:

  • P / N - Prompt or no promt flag
  • Parameter name
  • Parameter Type (Class Name)
  • Optional description

Example output:

$ jasperstarter params myreport.jasper P background java.awt.Image Background image P MyName java.lang.String Title of some component P MyDate java.util.Date

Command files

Every command, every option and every argument that JasperStarter accepts can also be saved in a file that is also linked to the @ Characters can be added to the call.

The file must contain one command / option / argument per line.

Example file (db.conf):

-t mysql -H localhost -n mydb -u folker

Example call with command file:

$ jasperstarter pr myreport -f view @ db.conf

Danger! The command file must not have any empty lines and only oneHave a line break without spaces at the end of the file!

Process reports

In order to process a report, the command pr specify which one needs the following options:

  • Input file (report definition, compiled report or filled report).
  • a space-separated list of output formats.
    • view and print are mutually exclusive, so print is ignored if view is specified.
  • a database type, if your report requires a database connection. The default value is none.
    • if the database type is not none the required connection parameters must be specified.

All other information is optional.

For the option (output) see section "File handling".

is now simply an argument. The order of options and this argument is not important, but an argument cannot be placed after an option that expects an indefinite number of arguments. These options are:

The following call will Not function:

$ jasperstarter pr -f view myreport.jasper

But these will:

$ jasperstarter pr -f print pdf -d myreport.jasper $ jasperstarter pr -f view -t mysql myreport.jasper -H localhost -u myuser -n mydb

The easiest way to avoid problems with arguments is to always place them in the first position immediately after the command, as shown in the following examples.

The minimum report without a database

The minimum options that are required to call up a report without a database are:

$ jasperstarter pr myreport.jasper -f view

The minimum database report

The minimum options that are required to call up a report that requires a database connection are:

$ jasperstarter pr myreport.jasper -f pdf -t mysql -H localhost -n mydb -u appuser

Display, print or export a previously filled report

You can fill a report at a time and display, print or export it at a later time.

Just fill in a report:

$ jasperstarter pr myreport.jasper -f jrprint -t mysql -H localhost -n mydb -u appuser

Display a previously filled report:

$ jasperstarter pr myreport.jrprint -f view

Reports with a CSV data source

The CSV file character set is preset to UTF-8. Other common character sets are cp1252 (Windows), ISO-8859-1, or ISO-8859-15 (Linux). You can change the CSV character set with the parameter --csv-charset specify.

Records are usually separated with a line break, but this doesn't have to be the case. The data record separator is preset to the system line break, which differs depending on your operating system. If you are using CSV files from another system, you must enter the correct line break with the parameter --csv-record-del to adjust:

  • Windows: \ r \ n
  • Linux / Mac: \ n

Fields can be separated by any character and optionally enclosed in quotation marks. The field separator is on , preset.

A simple example:

$ jasperstarter pr csv.jrxml -f view -t csv --data-file data.csv --csv-first-row

A slightly more complex example:

$ jasperstarter pr csv.jrxml -f view -t csv --data-file data.csv \ --csv-columns Name, Phone --csv-record-del = "\ n" --csv-field-del = " | " \ --csv-charset = cp1252

Reports with runtime parameters

Report parameters can consist of different types (classes). JasperStarter can generally handle all classes that have a constructor of the String type. In addition, JasperStarter has special routines for classes that do not have a constructor of the String type or that require special handling in some other way. These are:

Multiple parameters can be separated by spaces. A parameter has the following form:

  • <Surname>=<value>

Replace Surname with the parameter name of your report. Parameter names differ by Upper and lower case !

The type parameter date accepts a date in the following ISO format: YYYY-MM-DD

The type parameter locale can be either a two-letter ISO-639 language code or a combination of the ISO-639 language code and the ISO-3166 two-letter country code combined with an underscore. For example de or de_DE.

$ jasperstarter pr report.jasper -t mysql -u myuser -f pdf -H myhost -n mydb \ -o report -p secret -P CustomerNo = 10 StartFrom = 2012-10-01
The image parameter

A simple way to adapt a report is to pass a logo or a background image as a parameter. The following example will background used as parameter name for the picture:

  • Create a parameter in your report and change its properties:
    • Surname = background
    • Parameter class = java.awt.Image
  • Insert a picture in the report and change its properties:
    • Image expression = $ P {background}
    • Expression class = java.awt.Image
  • compile your report

Now you can process your report with JasperStarter:

$ jasperstarter pr report.jasper -t mysql -u myuser -f pdf -H myhost -n mydb \ -o report -p secret -P background = / tmp / mybackgroundimage.jpg
Specify parameters that contain spaces

Windows users in particular may need to specify filenames that contain spaces. There are two ways you can do this. Just put the value in quotation marks:

c: \ jasperstarter pr report.jasper -t mysql -u myuser -f pdf -H myhost -n mydb \ -o report -p secret -P background = "C: \ Temp Files \ My Image.jpg" otherValue = 1

or the whole parameter:

c: \ jasperstarter pr report.jasper -t mysql -u myuser -f pdf -H myhost -n mydb \ -o report -p secret -P "background = C: \ Temp Files \ My Image.jpg" otherValue = 1
Prompt for parameters

JasperStarter can be used with the option -a ask for report parameters.

Any parameter that has been defined in a report can be displayed. However, only those parameters are supported for input whose type (class) has a constructor for a character string (string) or for which a special routine is available.

The displayed parameters can be filtered with the following optional arguments:

  • a - all parameters (including system parameters)
  • ae - all empty parameters (parameters for which no value was given on the command line)
  • p - all user-defined parameters that have been marked for the query (this is the default setting if -a no argument was given)
  • pe - all empty user-defined parameters that have been marked for query
  • u - all user-defined parameters
  • ue - all empty custom parameters

In the following examples we assume a non-database report in which the following two parameters are defined:

  • MyDate (java.util.Date)
  • MyText (java.lang.String)

The user is asked for both parameters:

$ jasperstarter pr myreport.jasper -f view -a

The user is asked for both parameters. The parameter MyDate is already filled, but can be changed by the user:

$ jasperstarter pr myreport.jasper -f view -P MyDate = 2013-01-30 -a

The user will only look for the empty parameter MyText asked. The parameter MyDate is already filled and is not displayed:

$ jasperstarter pr myreport.jasper -f view -P MyDate = 2013-01-30 -a pe

Reports with resources

Reports can use various resources such as i18n resource bundles, icons or images.

If a resource is in the same directory as the report, the option is enough -r without specifying arguments:

$ jasperstarter pr myreport.jasper -f view -r

If a resource is contained in another directory or in a jar file, the path can be given as an argument:

$ jasperstarter pr myreport.jasper -f view -r myresources /

or

$ jasperstarter pr myreport.jasper -f view -r myresources.jar

File treatment

If the input file (option) was not found, first .jasper appended. If the file is still not found, will .jrxml added to the filename. This makes it possible to leave out the file extension.

If a .jrxml is used, it will be compiled and used in memory unless you specify the option, whereby the compiled report is saved as a file in the input Directory is written.

A .jrprint File can be used as input, but it must be given with the full filename.

If the output file or the directory (option) has been omitted, the higher-level directory of the input file and the base file name of the input file are used as the output file name:

(...) myreports / report1 -f pdf odt

or

(...) myreports / report1.jasper -f pdf odt

or

(...) myreports / report1.jrxml -f pdf odt

result in:

myreports / report1.odt myreports / report1.pdf

If output is an existing directory, the base name of input used as file name in this directory:

(...) myreports / report1.jasper -f pdf odt -o month01 /

results in:

month01 / report1.odt month01 / report1.pdf

If output Is NOT an existing directory, the base name is used as the file name:

(...) myreports / report1.jasper -f pdf odt -o month01 / journal.xyz

results in:

month01 / journal.xyz.odt month01 / journal.xyz.pdf