Description:
I have a single .bal file which imports a module that has native implementations. The cellery module .balo file is already copied to ~/.ballerina/balo_cache/ location. The following error is thrown at runtime when trying to compile the source code. The same code works when .bal file is added inside a project and .balo file is added as a dependency in the Ballerina.toml.
ballerina run stocks_build.bal "{\"org\":\"wso2\", \"name\":\"stock\", \"ver\":\"1.0.0\"}"
Compiling source
stocks_build.bal
error: celleryio:cellery:/src/cellery/cellery.bal:652:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.CreateCellImage
error: celleryio:cellery:/src/cellery/cellery.bal:664:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.CreateInstance
error: celleryio:cellery:/src/cellery/cellery.bal:673:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.ReadSwaggerFile
error: celleryio:cellery:/src/cellery/cellery.bal:682:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.ReadReference
error: celleryio:cellery:/src/cellery/cellery.bal:691:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.RunInstances
error: celleryio:cellery:/src/cellery/cellery.bal:695:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.RunTestSuite
error: celleryio:cellery:/src/cellery/cellery.bal:703:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.StopInstances
error: celleryio:cellery:/src/cellery/cellery.bal:711:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.CreatePersistenceClaim
error: celleryio:cellery:/src/cellery/cellery.bal:715:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.CreateSecret
error: celleryio:cellery:/src/cellery/cellery.bal:719:1: {ballerinax/java}CLASS_NOT_FOUND message=io.cellery.impl.CreateConfiguration
source:
import ballerina/io;
import celleryio/cellery;
public function build(cellery:ImageName iName) returns error? {
//Build Stock Cell
io:println("Building Stock Cell ...");
//Stock Component
cellery:Component stockComponent = {
name: "stock",
src: {
image: "wso2cellery/sampleapp-stock:0.3.0"
},
ingresses: {
stock: <cellery:HttpApiIngress>{ port: 8080,
context: "stock",
definition: {
resources: [
{
path: "/options",
method: "GET"
}
]
},
expose: "local"
}
}
};
cellery:CellImage stockCell = {
components: {
stockComp: stockComponent
}
};
return <@untainted> cellery:createImage(stockCell, iName);
}
public function run(cellery:ImageName iName, map<cellery:ImageName> instances, boolean startDependencies, boolean shareDependencies) returns (cellery:InstanceState[]|error?) {
cellery:CellImage stockCell = check cellery:constructCellImage(iName);
return cellery:createInstance(stockCell, iName, instances, startDependencies, shareDependencies);
}
public function main(string action, cellery:ImageName iName, map<cellery:ImageName> instances) returns error? {
return build(<@untainted> iName);
}
Steps to reproduce:
Affected Versions:
Ballerina 1.0.1
Language specification 2019R3
OS, DB, other environment details and versions:
macOS 10.14.2
Related Issues (optional):
Suggested Labels (optional):
Suggested Assignees (optional):
Including dependencies is not possible with a single .bal file since there is no way to define the dependencies. If you have dependencies, you need to specify them in a Ballerina.toml within a Ballerina project.
One option you can try is adding the dependant jars to the classpath using the -cp option during runtime.
This is actually a bug. When import celleryio/cellery is there, the build will pull the module from central and place it in home repository. Now lets say the celleryio/cellery has interop code where the jar files are in the celleryio/cellery balo file. Hence interop must work for single files as well.
As a temporary solution for ballerina 1.0.1, please patch the attached .jar file(inside the zip) to the
Most helpful comment
This is actually a bug. When
import celleryio/celleryis there, the build will pull the module from central and place it in home repository. Now lets say thecelleryio/celleryhas interop code where the jar files are in thecelleryio/cellerybalo file. Hence interop must work for single files as well.