I have the a jar with the following structure:
main-app/
├─ META-INF/
│ ├─ maven.org.rascalmpl.runmain/
│ │ ├─ pom.xml
│ │ ├─ pom.properties
│ ├─ MANIFEST.MF
├─ rascal/
│ ├─ Main.tpl
│ ├─ MyModule.tpl
├─ Main.rsc
├─ MyModule.rsc
and I'm writing an Evaluator to run function from the JAR, so far I have the following:
final GlobalEnvironment heap = new GlobalEnvironment();
final ModuleEnvironment top = new ModuleEnvironment("test", heap);
Evaluator eval = new Evaluator(vf, System.in, System.err, System.out, top, heap);
eval.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
eval.addRascalSearchPath(URIUtil.rootLocation("std"));
ISourceLocation tmp = URIUtil.correctLocation("jar", "", "/path/to/runmain-0.1.0-SNAPSHOT.jar!");
eval.addRascalSearchPath(tmp);
eval.doImport(null, "Main");
eval.doImport(null, "MyModule");
System.out.println(eval.getHeap().existsModule("Main")); // Check if module has been added to heap
eval.call("main", tmp, null);
When I try to run this, it just prints out false, and then the following exception:
Exception in thread "main" org.rascalmpl.interpreter.staticErrors.ModuleImport: Could not import module Main: can not find in search path
How can I access either the .tpl files or .rsc files in the JAR to call arbitrary functions?
P.S: When I compiled the JAR the RASCAL.MF was not included in the output, is it necessary?
If the
run-mainjar has aMETA-INF/RASCAL.MFin it withProject-Name: run-mainin it, then the Rascal URI name resolver automatically registerslib://run-mainand lets it point to the root of the jar. So that would enable you to do this:Instead of this, you can also use the
jarscheme. But this requires you to find the jar file location:After the
!is where the path into the jar files starts, and where.rscfiles can be found. The earlierlibscheme does exactly that, but automatically based on searching through the classpath for RASCAL.MF files.