Reputation: 2663
I am trying to import an external jar into ballerina. In this case it is from nd4j-native-platform-1.0.0-beta5.jar downloaded from maven-central. I can't figure out what the problem is.
The config of my Ballerina.toml file is as follows:
Ballerina.toml
[project]
org-name= "user_name"
version= "0.1.0"
[platform]
target = "java8"
[[platform.libraries]]
path = "/Users/username/Code/Workspace6/ballerina-hackathon/ml-connector/java_dependencies/deeplearning4j-modelimport-1.0.0-beta5.jar"
modules = ["ml_service"]
The file (load_model.bal) in my module named "ml_service" to load:
load_model.bal
import ballerinax/java;
function loadModel() returns handle = @java:Method {
name: "ClassPathResource",
class: "org.nd4j.linalg.io"
} external;
public function main() {
var load = loadModel();
}
The error I am getting when I try to build is as follows:
computername:ml-connector username$ ballerina build ml_service
Compiling source
user_name/ml_service:0.1.0
Creating balos
target/balo/ml_service-2019r3-java8-0.1.0.balo
error: user_name:ml_service:load_model.bal:9:1: {ballerinax/java}CLASS_NOT_FOUND message=org.nd4j.linalg.io
Upvotes: 2
Views: 335
Reputation: 2663
I found out what the problem was, the jar that I had did not have the class ClassPathResource in it. To add to this, the code should have been modified in the load_model.bal file. The function classPathResource had to be declared as a Constructor and not a Method as I had previous declared it to be. It also had to take a parameter of type string. I have attached the code I used below.
load_model.bal
import ballerinax/java;
import ballerina/io as _;
function loadModel(handle path) returns handle = @java:Constructor {
class: "org.nd4j.linalg.io.ClassPathResource"
} external;
public function main() {
var load = loadModel(java:fromString("model_path"));
}
Upvotes: 5