TCR BIRT Javascript failed to call java class [message #666963] |
Mon, 25 April 2011 02:33  |
Eclipse User |
|
|
|
Hi Experts,
Could anybody please help me out? Please tell me where I should put my jar files?(I tried location: /opt/IBM/tivoli/tip/products/tcr/lib/birt-runtime-2_2_1/Repo rtEngine/lib)
I am new to TCR BIRT report, and using TCR with birt 2.2.1. I have a headache issue about javascript call my java class. I need to write a group of java classes to access RSA as datasource, and use java script of dataset to call my java classes. All of my java classes could not be found by BIRT run-time. So, I need to figure out what's the reason by trying a simplest java class called by a javascritp of fetch function which belongs to a dataset.
I tried very smile java class. It has very simple function as below:
=============== My simple java class ==============
package com.hpshi;
public class HPTest2 {
public HPTest2(){
}
public String getValueOfString( String field ){
String ret = "HPTest2 0420:" + field;
return ret;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(new HPTest2().getValueOfString("Hello2!"));
}
}
==========java class caller: Java script ==========
// Data Set Fetch function
// In dataset fetch javascript. I have script below:
importPackage( Packages.com.hpshi );
instance = new HPTest2();
row["SEX"] = "Male";
row["NAME"] = "Hongping";
row["NAME"] = instance.getValueOfString("NAME");
row["AGE"] = 29;
logToDebugWindow("age="+29);
count++;
if ( count < 3)
return true;
else
return false;
================================
It works very well in BIRT-ALL-IN-ONE designer. However, when I put it into our runtime env. It doesn' work at all. It complains my java class "HpTest2" is not defined.
Here is my envionment:
Tivoli Common Report:
birt-runtime: 2.2.1
OS: is AIX
Here is what I did for deploying.
.I put the java class in a jar file. And I put the jar file into ReportEngine/lib (According FAQ information provided by http://wiki.eclipse.org/BIRT/FAQ/Scripting)
The jar file is ok. Because, it works in the ALL_IN_ONE design env, when I removed HPTestd2.class file as long as I added the jar file into build path as external jar.
.Restart tcr server. by stopTCRserver.sh and startTCRserver.sh
However, I found a workaround way which is ugly to make it working. Since I found the class path by using java.lang.System.getProperty( "java.class.path" ); I replaced one of jar files in the classpath , which looks like not used, with my jar file. My simple java class was called by the fetch java script successfully by this way. However, the problem is that this is only simple java class, and my real java classes have many dependant classes inside jar files. So this workaround doens't help me out of the difficulty. I have been struck in this issue 3 weeks, please help me out!!!
Many thanks,
Hongping Shi
[Updated on: Mon, 25 April 2011 10:38] by Moderator
|
|
|
Re: TCR BIRT Javascript failed to call java class [message #667081 is a reply to message #666963] |
Mon, 25 April 2011 11:15   |
Eclipse User |
|
|
|
I assume you are using the Report Engine API?
If so did you use:
config = new EngineConfig();
HashMap hm = config.getAppContext();
hm.put( EngineConstants.APPCONTEXT_CLASSLOADER_KEY,
MyClass.class.getClassLoader());
config.setAppContext(hm);
You can specifically set the property for the classpath like:
config.setProperty( EngineConstants.WEBAPP_CLASSPATH_KEY,
classpathstring);
Jason
On 4/25/2011 2:33 AM, hongping wrote:
> Hi Experts,
> Could anybody please tell me where I should put my jar files?(I tried
> location: /opt/IBM/tivoli/tip/products/tcr/lib/birt-runtime-2_2_1/Repo
> rtEngine/lib)
> I am new developer for TCR BIRT report. I am using TCR with birt 2.2.1.
> I have a headache issue about javascript call my java class. I need to
> write a group of java classes to access RSA as datasource, and use java
> script of dataset to call my java classes. All of my java classes could
> not found by BIRT run-time. So, I need to figure out what's the reason
> by trying a simplest java class called by a javascritp of fetch function
> which belongs to a dataset.
> I tried very smile java class. It has very simple function as below:
> =============== My simple java class ==============
> package com.hpshi;
>
> public class HPTest2 {
>
> public HPTest2(){
> }
>
> public String getValueOfString( String field ){
> String ret = "HPTest2 0420:" + field;
> return ret;
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> // TODO Auto-generated method stub
> System.out.println(new HPTest2().getValueOfString("Hello2!"));
> }
>
> }
>
> ==========java class caller: Java script ==========
> // Data Set Fetch function
> // In dataset fetch javascript. I have script below:
> importPackage( Packages.com.hpshi );
> instance = new HPTest2();
>
> row["SEX"] = "Male";
> row["NAME"] = "Hongping";
> row["NAME"] = instance.getValueOfString("NAME");
>
> row["AGE"] = 29;
> logToDebugWindow("age="+29);
>
> count++;
> if ( count < 3) return true;
> else
> return false;
> ================================
>
> It works very well in BIRT-ALL-IN-ONE designer. However, when I put it
> into our runtime env. It doesn' work at all. It complains my java class
> "HpTest2" is not defined.
>
> Here is my envionment:
> Tivoli Common Report:
> birt-runtime: 2.2.1
> OS: is AIX
>
> Here is what I did for deploying.
> I put the java class in a jar file. And I put the jar file into
> ReportEngine/lib (According FAQ information provided by
> http://wiki.eclipse.org/BIRT/FAQ/Scripting)
> The jar file is ok. Because, it works in the ALL_IN_ONE design env, when
> I removed HPTestd2.class file as long as I added the jar file into build
> path as external jar.
> Restart tcr server. by stopTCRserver.sh and startTCRserver.sh
>
> However, I found a workaround way which is ugly to make it working.
> Since I found the class path by using java.lang.System.getProperty(
> "java.class.path" ); I replaced one of jar files in the classpath ,
> which looks like not used, with my jar file. My simple java class was
> called by the fetch java script successfully by this way. However, the
> problem is that this is only simple java class, and my real java classes
> have many dependant classes inside jar files. So this workaround doens't
> help me out of the difficulty. I have been struck in this issue 3 weeks,
> please help me out!!!
>
> Many thanks,
>
> Hongping Shi
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06007 seconds