Skip to content

DasJott/mkjni

Repository files navigation

mkjni

C code is fast - Vala code is as fast

If you don't know Vala, you must know, that it is a language, as easy as C# but it compiles first to C and then to machine code. So there is the speed advantage of C code and the easyness of C# syntax!

Call Vala code from Java

Vala code might be faster or just better to write or simply more beautiful.
Write some functionality in Vala, specify a class you want to "export" to Java and mkjni creates a jni lib and the Java Class for you.
So it feels like you could call the Vala class from Java!

Limitations:

Only possible types:

You MUST ONLY use the following types: string, int, int8, double, float, char, bool, string[], int[], int8[], float[], double[], char[]
The type int8 in Vala is transformed to byte in Java! So is int8[] in Vala transformed to byte[] in Java

There is created only ONE instance of the Vala class, not matter how many instances you create in Java!
It is only tested on Ubuntu Linux and won't run on Windows. This might change in the future.

Usage

mkjni [PARAMS][OPTIONS] <FILE(S)>

Params (must-have):

Parameter Description
-c, --class <class name> A class within the vala file to generate the jni from
-l, --lib <lib name> Please specify the desired name of the library
The name is w/o lib prefix and .so suffix!

Options:

Option Description
-p, --pkg <package(s)> Packages to be included (Vala --pkg and pkg-config) *
-j, --jns <package> The Java namespace (package) to be created
-cc <compiler> The compiler to be used (default: gcc)
-X --ccmd <command(s)> Additional command, passed to the compiler *
-V --vcmd <command(s)> Additional command, passed to valac *
-e --ext <lib(s)> External dependency's library name. Don't forget the the vapi file. *
-d Create Java file in package directory
-n Not compile, just generate files
-o Only compile, do not link
-t Use tmp directory for processing
-v Verbose - tell what's going on
-h, --help for showing help

*) This option can be used multiple times in one call or takes comma separated list

Note: mkjni creates all files (and directories for java packages) in the directory where it is called.

Examples:

*mkjni -v -t -c MyClass -j de.dasjott.myclass -l superjni .vala
*mkjni -v -t -c MyClass -j de.dasjott.myclass -l superjni -e addlib addlib.vapi .vala
*mkjni -c MyClass -l superjni -V --disable-assert -V --target-glib=2.32 -X -O3 -p gio-1.0 .vala
*mkjni -c MyClass -l superjni -V --disable-assert,--target-glib=2.32 -X -O3 -p gio-1.0 .vala

You should be provided with a result like libsuperjni.so for these examples and a Java file MyClass.java in your current directory.

Bugs

If you find bugs, don't feed them, so they'll die over time.
You could as well fix them yourself, as you have the code.
Or you just call me to come by to squish them. Maybe I will ;)
If you like, please buy me a coffee. Thank you! :-)

About

Call Vala code from Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages