problem in import package in birt script

sandeepBha
sandeepBha Member
edited February 11, 2022 in Analytics #1
hi all,

I write below code in script .

importPackage( Packages.java.io );
importPackage(Packages.java.text.SimpleDateFormat);
outFile = new FileWriter("../sandfilelogtoday.txt");
out = new PrintWriter(outFile);
sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss:ms");

out.println(sdf.format(new Date()).toString()+"-- intializern");
out.close();

when i run this report it will get below error

ReportDesign (id = 1):
- Unhandled exception when executing script.
Caused by: org.eclipse.birt.core.exception.CoreException:
There are errors evaluating script "importPackage( Packages.java.io );importPackage(Packages.java.text.SimpleDateFormat);outFile = new FileWriter("../sandfilelogtoday.txt");out = new PrintWriter(outFile);sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss:ms");out.println(sdf.format(new Date()).toString()+"-- intializern");out.close();"

Function importPackage must be called with a package; had "[JavaClass java.text.SimpleDateFormat]" instead. (/report/method[@name="initialize"]#2).

what should i do, please help soon

sandeep

Comments

  • Virgil Dodson
    Virgil Dodson E Community Administrator
    edited December 31, 1969 #2
    Hi sandeep,

    Remove SimpleDateFormat from your importPackage statement since it is not a Package. That line should look like:
    importPackage( Packages.java.text );

    I created a working example with BIRT 2.3.0 enclosed
    Warning No formatter is installed for the format ipb
  • SreyaA
    SreyaA Member
    edited December 31, 1969 #3
    There are 2 java files under src/test folder.
    Test.java and Test2.java. I'm able to invoke the method from both classes.
    My rptdesign file is one level higher than this. Its in /package folder.
    I'm unable to invoke the Test2.java from rptdesign file.

    Also, there is no error when i give this statement in Script.

    importPackage (Packages.src.test)

    What could be wrong. Pls, help soon.
  • CiapiniCiapini
    edited August 2, 2022 #4

    Hi everybody,

    I had a similar issue.

    I create a jar Called QrCodeGenerator_rev20220729 and I put it in birt with this way:

    Window -> Preferences -> Report Design -> Classpath -> Add External Jars

    I script :

    importPackage( Packages.qrCodeGenerator.* );


     vars["qrCode"] = QrCodeGenerator.getQRCodeIme(this.getRowData().getColumnValue("code"), 50, 50);


    But birt gave me back that error:

    There are errors evaluating script "importPackage( Packages.qrCodeGenerator.* );


     vars["qrCode"] = QrCodeGenerator.getQRCodeIme(this.getRowData().getColumnValue("code"), 50, 50);":

    ReferenceError: "QrCodeGenerator" is not defined.



    The Jar is structured:

    QrCodeGenerator_rev20220729 as jar / qrCodeGenerator as package / QrCodeGenerator.class as class



    I'm really new about external jar with BIRT how can i solve it?


    You can find jar file (as zip file) attached.



    Hope hear you soon,

    Best regards