Marouane Gazanayi
Marouane Gazanayi

Reputation: 5183

Import a class in Scripting java (javax.script)

I want to import a class that I made in my project, into my script I did this but it doesn't work:

    function doFunction(){
 //Objectif Mensuel
 importPackage(java.lang);
 importClass(KPDataModel.KPData.KPItem); //ERROR HERE, this is my class that I want to import

 KPItem kpItem = kpItemList.get(0);
 System.out.println(kpItem.CellList.get(2).Value);
 System.out.println("-------");
 var proposedMediationSum = Integer.parseInt(kpItemList.get(0).CellList.get(2).Value);
 var refusedMediationSum = Integer.parseInt(kpItemList.get(0).CellList.get(3).Value)
 var totalMediation = proposedMediationSum + refusedMediationSum;

 kpItemList.get(0).CellList.get(4).Value = totalMediation;

}

Upvotes: 5

Views: 1622

Answers (1)

Marouane Gazanayi
Marouane Gazanayi

Reputation: 5183

Well, thnx a lot, I found that the problem comes from the import. This is what it said in the Oracle website :

The Packages global variable can be used to access Java packages. Examples: Packages.java.util.Vector, Packages.javax.swing.JFrame. Please note that "java" is a shortcut for "Packages.java". There are equivalent shortcuts for javax, org, edu, com, net prefixes, so pratically all JDK platform classes can be accessed without the "Packages" prefix.

So, to import my class I used : importClass(Packages.KPDataModel.KPData.KPItem);

Upvotes: 4

Related Questions