Worklight adapter It is not a function, it is “obj

2020-05-06 07:53发布

问题:

After deploying worklight adapter onto production server, when adapter makes a call to java code from javascript I get an error:

rocedure invocation error. Ecma Error: TypeError: Cannot call property updateProposal in object [JavaPackage com.idit.smartphone.managers.ProposalManager]. It is not a function, it is "object". (IDITBackend-impl.js#119) 

I have tried calling a test function in a class without parameters and it's still not working my class looks like

package com.idit.smartphone.managers;
public class ProposalManager {
    public static String test(){
        return "Successss";
    }
}

and the call is:

function finishTask(policyExtNum, answers, closeUnderwriting){

   WL.Logger.info("Service finishTask called.");
   var proposal = getProposalForUpdate(policyExtNum);
   WL.Logger.info("finishTask got proposal");
   var updatedProposal = com.idit.smartphone.managers.ProposalManager.test();
   var result = sendProposalForUpdate(updatedProposal);
   WL.Logger.info("finishTask updated proposal");

   return result;
}
  • I'm using the latest version of worklight that was published yesterday. 6.0.0.20130917-1749 deployed on tomcat 6
  • It works on worklight studio, the problem only when I upload the adapter to tomcat
  • I'd tried all the solutions to other question like mine in this forum

回答1:

a search would have given you a couple of questions/answers already: i want to call a java class from the worklight adapter ; ECMA TypeError calling Java class from Worklight adapter ; Ecma Error: TypeError: Cannot call property

we had that problem several times and it always had something to do with a corrupted eclipse .project file. What happens is that the Java Class you have does not get built and does not get added to your worklight.war file. When you deploy your app, the compiled class is missing on the server and the ECMA error tells you that in a very cryptic way.

One solution we found was to open the properties of the WL project with a right click go to the Java Build Path and move some of the entries UP and DOWN using the buttons there. After closing the properties dialog eclipse should rewrite the .project file and the build should work.

Another thing we did sometimes was to add a new class to the project/server/java part of the project using the eclipse New-Class wizard, clean and rebuild the project and then remove the class again. Maybe even start eclipse with the option -clean at the end of the startup string that it uses.



回答2:

in your eclipse preferences set java compiler level to java 1.6 and rebuild.