Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

}
like image 468
Marouane Gazanayi Avatar asked Oct 15 '22 03:10

Marouane Gazanayi


1 Answers

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);

like image 164
Marouane Gazanayi Avatar answered Oct 20 '22 20:10

Marouane Gazanayi