https://kotlinlang.org logo
#javascript
Title
# javascript
s

Shachar Levy

05/31/2023, 1:40 PM
Hi all, I have a question maybe someone here will have an idea. Let's say I have a library written for Java (specifically Apache JEXL). We would like to compile this jar to javascript. Our use case is that we have business expressions written in JEXL (for example if(foo > 5) 'Yes' else 'No; ) and we want to be able to run these expressions also in our client side (written in typescript angular). unfortunately there isn't a library apache JEXL for javascript (only something else that is not compatible) . So that's why we want to take the Apache JEXL jar, compile it to Javascript, and use that as a dependency in the client side. Is it possible using Kotlin? any other ways you think we can achieve this? thank you
v

Vampire

05/31/2023, 2:10 PM
You cannot simply morph Java bytecode to JavaScript. Java is to JavaScript like car to carpet. You even couldn't do that with Kotlin generated bytecode, but instead would need to write the code in Kotlin/JS or Kotlin Multiplatform and then compile to JavaScript "directly". There are tools that let you do such a conversion depending on which APIs are used like https://leaningtech.com/cheerpj/ or https://www.teavm.org/. Just have a look at those or Google for it.
s

Shachar Levy

05/31/2023, 2:15 PM
thank you! but i'm still missing something. If Intellij can take java code and transfer it to Kotlin code (like with the copy paste feature) So theoretically I can create a new project- copy paste all the code from JEXL apache, which will transfer it to Kotlin (let's assume with no errors) and then define the project to be from kotlin to JS .
v

Vampire

05/31/2023, 2:19 PM
Good luck, you will need it 🙂
😅 1
😄 1
l

Landry Norris

06/02/2023, 6:46 PM
If the code is pure kotlin with no dependencies, the answer is yes. You'll definitely have to handle differences in libraries.
5 Views