Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
My JAR files in BIRT Reports
millvall
Hi Folks,
I must be missing something simple, but can?t see it.
I?ve created a JAR file with one simple class + one simple method to test my problem.
package birtRoutines;
public class birt101 {
public birt101() {}
public String hello101() { return "Hello from 101"; }
}
I added the external JAR file to my OS BIRT 2.6.2 environment using...
Windows > Preferences > Report Design > Classpath > Add External JARs.
Then added code below to initialize:
importPackage(Packages.birtRoutines.*);
var br = new birtRoutines.birt101();
var s = br.hello101();
Preview complains with:
ReferenceError: "birtRoutines" is not defined.
To check I was on the right track, I also added another external JAR: jaxrpc.jar
Then added the code below..
importPackage(Packages.javax.xml.rpc.*);
var jxfilename = new javax.activation.FileDataSource("AnyFileName.txt");
var ds = new javax.activation.DataHandler(jxfilename);
It works fine! No need to add the JAR to in Resources property of the .rptdesign.
It must be a doozy, I just can?t see for looking.
Thanks
Milt.
STEPS.
1) Unzip file attached. Start OS BIRT 262
2) Add the 2 JAR files to the environment using:
Windows > Preferences > Report Design > Classpath > Add External JARs.
JARS are
-) jaxrpc.jar
-) birtRoutinesEnterprise.jar
The entire code in birtRoutinesEnterprise.jar is below in case you want to re-build:
package birtRoutines;
public class birt101 {
public birt101() {}
public String hello101() { return "Hello from 101"; }
}
3) Copy the report: usingJarFiles.rptdesign to any project. (It uses Classic Models)
4) Run report. Big yellow label at top shows object types created from jaxrpc.jar
5) Remove comments from these lines in Initialize
//var br = new birtRoutines.birt101();
//var s = br.hello101();
Then re-run.
You should get birtRoutines is not defined.
- eom -
Find more posts tagged with
Comments
millvall
Please use the ZIP file: usingJarFiles.zip for steps.
(Ignore previous Milton-JarFiles.zip)
Thanks
Milt.
Yaytay
I had a play to see if I could work out what was going on, and all I found is that this works:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>var br = new Packages.birtRoutines.birt101();</pre>
and this doesn't:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>var br = new birtRoutines.birt101();</pre>
It looks like importPackage is where the problem lies, but I'm afraid I don't know why.
millvall
Hi Yaytay,
Thanks for the solution. Strange how the syntax differs from using javax.xml.rpc.
I confirmed your syntax works. I also found this worked:
// importPackage(Packages.birtRoutines.*); // BAD
importPackage(Packages.birtRoutines); // GOOD
var br = new birt101();
var s = br.hello101();
Thanks Again.
Milt.
Yaytay
<blockquote class='ipsBlockquote' data-author="'millvall'" data-cid="95173" data-time="1328651509" data-date="07 February 2012 - 02:51 PM"><p>
// importPackage(Packages.birtRoutines.*); // BAD<br />
importPackage(Packages.birtRoutines); // GOOD<br /></p></blockquote>
Well that's odd, I tried that and it didn't work! Ho hum.<br />
<br />
That makes sense though, (Packages.birtRoutines.*) is trying to import packages below birtRoutines, whereas (Packages.birtRoutines) is just trying to import birtRoutines itself.<br />
<br />
Jim