Java 在 jaspersoft studio 中使用外部 JAR 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23863343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 08:36:07  来源:igfitidea点击:

use external JAR file in jaspersoft studio

javajasper-reports

提问by Samira Khorshidi

I have project in iReport,I want to build this in jasper studio,in that I use some external jar file to convert date,but in jasper studio I cant use them,I add those jar file in right click on project folder > properties > java build path > libraries > add External JARs..,iI get error when i want to see report preview :

我在 iReport 中有项目,我想在 jasper studio 中构建它,因为我使用了一些外部 jar 文件来转换日期,但是在 jasper studio 中我不能使用它们,我将这些 jar 文件添加到其中,right click on project folder > properties > java build path > libraries > add External JARs..当我想要时出现错误见报告预览:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. com.ghasemkiani.util.icu.PersianDateFormat cannot be resolved to a type
                value = new com.ghasemkiani.util.icu.PersianDateFormat("yyyy/MM/dd").format(((java.sql.Timestamp)field_ORDERDATE.getValue())); //$JR_EXPR_ID=9$
                            <---------------------------------------->
2. com.ghasemkiani.util.icu.PersianDateFormat cannot be resolved to a type
                value = new com.ghasemkiani.util.icu.PersianDateFormat("yyyy/MM/dd").format(((java.sql.Timestamp)field_ORDERDATE.getOldValue())); //$JR_EXPR_ID=9$
                            <----------------------------------------> 

so,my question is : how can I add external jar file and use it?

所以,我的问题是:如何添加外部 jar 文件并使用它?

回答by Vimal Bera

In order to get the JRXML attached working what you will need to do is

为了使附加的 JRXML 工作,您需要做的是

Import the jar Tools(in the iReport Menu bar )-----> Options ----- > Click on Claspath Tab ------> ADD Jar -----> choose the JAr file (I Think You missed this step You need to import the JAR file through iReport through the above described process, no need of using IDE for classpath setting use iReport only)

导入 jar 工具(在 iReport 菜单栏中)-----> 选项 ----- > 单击 Claspath 选项卡 ------> 添加 Jar -----> 选择 JAr 文件(我认为你错过了这一步你需要通过上述过程通过 iReport 导入 JAR 文件,不需要使用 IDE 进行 classpath 设置,只使用 iReport)

It works for me.

这个对我有用。

回答by BigAl

'In Jaspersoft Studio there is no longer a big unique classpath for the whole application like in iReport.

'在 Jaspersoft Studio 中,不再像 iReport 那样为整个应用程序提供一个很大的独特类路径。

Each report is supposed to be part of a project. The project has a classpath, and here is where you should add the jars you need.

每个报告都应该是一个项目的一部分。该项目有一个类路径,您应该在此处添加所需的 jar。

All is done by opening the projects view and right click the project folder with which you are working on. By default, new reports are created in the project "My Reports".'

所有这些都是通过打开项目视图并右键单击您正在处理的项目文件夹来完成的。默认情况下,在“我的报告”项目中创建新报告。

Answer From JasperCommunity

来自 JasperCommunity 的回答

回答by Rajesh Sirsikar

You have added the JAR file in the right location, but the issue (looking at the error message) is that the reference to the external class has not been provided.

您已在正确的位置添加了 JAR 文件,但问题(查看错误消息)是尚未提供对外部类的引用。

Select the Field or Variable which needs to be run the new class (from JAR file). change the Class of the fields to your new class and run the report. You will have no errors then.

选择需要运行新类的字段或变量(来自 JAR 文件)。将字段的类更改为您的新类并运行报告。那样你就没有错误了。

回答by EA0906

After you have added jar file to build path you have to restart your Jasper Studio.

将 jar 文件添加到构建路径后,您必须重新启动 Jasper Studio。