Hi all, I have a question maybe someone here will ...
# javascript
s
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
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
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
Good luck, you will need it 🙂
😅 1
😄 1
l
If the code is pure kotlin with no dependencies, the answer is yes. You'll definitely have to handle differences in libraries.