Closed eix128 closed 3 years ago
JTransc doesn't support JavaScript to Java translation. I'm afraid, not even related and not its focus.
If you want polyglot development you might want to take a look to GraalVM: https://www.graalvm.org/ you should be able to mix languages with that one.
The focus of JTransc is JVM bytecode (mostly Kotlin) into other languages with an AOT approach in mind like CLI or games, more than using it with dynamic languages like JS. GraalVM or Kotlin multiplatform right now AFAIK don't generate C++ source for example that could allow to target non-standard platforms like homebrew consoles. When JTransc started GraalVM didn't exist, nor Kotlin/Native.
I know GraalVM but GraalVM doesnt generate javascript library to java wrapper.
For example on here : https://blog.yuzutech.fr/blog/java-api-on-javascript-lib-graalvm/
chroma.min.js library will be used on java But author must write the wrapper manually to use in java directly. This is something like JNI for C++ that we need to write wrap manually all functions.
package org.chroma;
import org.graalvm.polyglot.Value;
import java.io.IOException; import java.net.URISyntaxException; import java.util.List;
public interface Chroma {
Chroma darken();
Chroma saturate(int value);
String hex();
List
static Chroma create(String color) { try { Value chroma = GraalVMChroma.create().getChroma(); Value instance = chroma.newInstance(color); return new ChromaInstance(instance); } catch (IOException | URISyntaxException e) { throw new RuntimeException("Unable to instantiate Chroma GraalVM"); } } }
and this class written manually:
package org.chroma;
import org.graalvm.polyglot.Value;
import java.util.ArrayList; import java.util.List;
public class ChromaInstance implements Chroma {
private Value chromaInstance;
public ChromaInstance(Value chromaInstance) { this.chromaInstance = chromaInstance; }
@Override public Chroma darken() { return new ChromaInstance(chromaInstance.getMember("darken").execute()); }
@Override public Chroma saturate(int value) { return new ChromaInstance(chromaInstance.getMember("saturate").execute(value)); }
@Override public String hex() { return chromaInstance.getMember("hex").execute().asString(); }
@Override
public List
I want these classes generated automatically.So i blindly use js library inside java.
It looks like a lot of pain to have to implement that yourself. But well, JTransc is not intended for that. JTransc includes code to handle JVM bytecode, not to parse JS or TypeScript definitions.
So I'm afraid, you will have to search elsewhere for that.
Going to close the issue since this is not possible.
Hi , is it possible to use javascript library in Java applications? There are lots of growing javascript libraries avalible.I want to use them in my current Java application without any Runtime.
does jtransc supports javascript to java translation ?