Reuse java (.jar) components in extension's backend

I would like to reuse java (.jar) components in my extension’s backend, so that 1. I can instantiate the java classes; 2. call it’s methods and 3. pass the return values to the extension’s frontend. Can anyone suggest a mechanism for this? A sample would be very helpful.

[original thread by rs]

Hi, you can spawn java process with child_process node js module and communicate with it for example via JSON-RPC over stdin.

https://www.theia-ide.org/doc/Json_Rpc.html explains how to configure communication between frontend and backend via JSON-RPC

https://www.eclipse.org/community/eclipse_newsletter/2017/may/article2.php explains how to use LSP4J to implement custom JSON-RPC protocol with java, for node part you will need to use vscode-jsonrpc (it comes together with Theia core)

[rs]

Sorry, I’m not an expert in java, can we use reflection concept and instantiate java classes to use it’s methods and subscribe to it’s events?

[Anatoliy Bazko]

yes, you can but not inside node process. At leas I am not aware. What you can do is to write a java program where you can use reflection and then run this program using child_process from theia backend