Some days ago, i got a requirement that i need to load an external scala file in my Scala application and have to use that. To use that file, it needs to be compile first and then can be used in the application.
The location of that external file can be anything apart from your project.
The structure of external file is fixed and should be define in your project i.e. class name and method signature.
Arguments and return type of the method can be vary according to our requirement.
Firstly we will define the dependencies in build.sbt :
Now, we need to define the code which will compile and load the external file in our application.
filePath is the path of external file which needs to be loaded.
You will notice the import statement as well :
This import is there because abstract class ExternalProcessing needs to be import in external file code as well otherwise type ExteranlProcessing not found compile time error will be there.
Now, we need to use externally loaded file as below:
Full code :
Get full code here
Hope this will be useful for you.
Happy Blogging. !!!