Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: Problem in invoking java code form java script value

  1. #1
    Join Date
    Jul 2009
    Posts
    6

    Default Problem in invoking java code form java script value

    I am trying to call my custom java code from Modified Java Script Value in following manner:
    var rs = new Packages.com.abc.report.ReportService(); where ReportService is a class in package com.abc.report

    1. With this, I get following error:
    General error executing script:
    TypeError: [JavaPackage com.abc.report.ReportService] is not a function, it is object. (script#5)

    Analysis: Looks like Here it is considering the constructor as a function instead of Object construction

    2. on the other hand i added a dummy static method add(a, b) and called it as var rs = new Packages.com.abc.report.ReportService().add(1, 1);

    In such case I get following error:
    General error executing script:
    TypeError: Cannot call property add in object [JavaPackage com.globallogic.velocity.report.ReportService]. It is not a function, it is "object". (script#5)

    Analysis: Looks like Here it is considering the invoked method as a property instead of a method.


    3. When I try the sample code for Base64 encode/decode (JavaScript - Base64 Decoder and Encoder.ktr ), it works absolutely fine

    What i have done:
    1. Compiled the java code (a single .class file), built a jar
    2. copied that jar to libext folder of data-integration tool.
    3. I can see jar getting into classpath

    Could some one point me in right direction in terms of what I may be missing based on errors listed above.

    Appreciate your help
    Last edited by rupeshkp; 07-15-2009 at 03:09 AM.

  2. #2
    DEinspanjer Guest

    Default

    That type of error usually means that the Rhino engine is not seeing the class you are attempting to use.

    If you are definitely seeing the jar get into the classpath, next, I'd double check that the jar contains your class exactly as referenced.

    You can verify whether the JS step is seeing your class properly by Alerting it like this:

    Alert(com.foo.bar.MyClass);

    If the Alert indicates it is a JavaClass then it found your class. Otherwise it will say it is a JavaPackage.

  3. #3
    Join Date
    Jul 2009
    Posts
    6

    Default

    Your observation is correct, with Alert it shows class as Package. So now I need to find out why Rhino script is not able to get the Java class. I have cross checked the class in jar and it has all the needed instructions as we want.

  4. #4
    DEinspanjer Guest

    Default

    I hate to say it, but it seems most likely that you are suffering some sort of user error. Either the class isn't in the jar that is actually getting loaded, or the wrong jar is getting put into libext or something.

    If you are using Kettle 3.2, you could double check this by trying to invoke your class through the "User Defined Java Expression" step. That step uses a completely different method for accessing Java classes, and if it can't find your class either, you'll know something is up with the files in your classpath.

  5. #5

    Default

    Ran into this error message myself, turns out to be very misleading, root cause was Jar file missing from lib/ folder.

    Attempts to set the CLASSPATH for kitchen.sh have no effect. You really have to hack kitchen.sh or copy the jar into data-integration/lib.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.