0

I know that it is possible to generate the JNI given a Java implementation using javac but is there a way to do the opposite (a "cjava")?

So if I have something like this:

mypackage/mylib.h:

void helloWorld();

mypackage/mylib.c:

#include <iostream>

void helloWorld() {
    std::cout << "Hello World!" << std::endl;
}

Shouldn't it be possible to generate the JNI like

mylib-jni.c:

#include "mypackage/mylib."

JNIEXPORT jlong JNICALL Java_mypackage_helloWorld() {
    helloWorld();
}

and

Mylib.java:

package mypackage;

public class Mylib {    
    public native void helloWorld();    
}

etc.

Somehow I am not stumbling upon something like that.

1
  • Have you looked at JNA (and the related JNAerator) or SWIG? Commented Aug 2, 2019 at 11:42

1 Answer 1

0

Try antlr. It has a grammar file for C++ and gives you full control.

For the generation of java you could use the cgV19 i hust released. My picture is:

parse the C++ file with antlr and build a model loader for cgV19 with it. cgV19 uses this C++ parser to load a model give cgV19 a cartridge that can generate your java files from that model

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.