skip to content
An anime girl with glasses

Call Java Functions from Rascal

/ 2 min read

Rascal 🤝 Java

The Problem

I have my Rascal code in one project, while having my Java project separately in another one, to keep things a little bit cleaner. However, I have to call Java functions from tRascal which makes everything a bit tricky.

My (crappy) solution

In the Java / Gradle side of things you add the following (in my case it is a Kotlin project, so the syntax for Gradle is slightly different). Keep in mind that you need to add the *.jar to your project resources folder.

Java Side

dependencies {

Then add a Java class with some functionality:

package com.sample;
import io.usethesource.vallang.IValueFactory; // This interface is important, otherwise
// it won't work

public class Teste {
    private final IValueFactory vf; // Boilerplate code to make it work

    public Teste(IValueFactory vf) {
        this.vf = vf;

    public void testeJava() { // The actual function
        System.out.println("it worked");

And build it with your gradle script.

Rascal Side

In the Rascal side of things you add the following code:

java void testeJava();

In your Rascal project, go to the pom.xml and add the local dependency of you build

    <systemPath>*INSERT THE PATH TO THE BUILT JAR*</systemPath>

You might need to execute a mvn clean install to make it work. Open up a new Rascal terminal, import the Module where you use the java function call and just call it (in this case testeJava())