{"id":17722656,"url":"https://github.com/christopherhx/libjnivm","last_synced_at":"2025-05-06T21:22:54.462Z","repository":{"id":51031532,"uuid":"217309932","full_name":"ChristopherHX/libjnivm","owner":"ChristopherHX","description":"Pseudo Java Native Interface implement Java functions in C++","archived":false,"fork":false,"pushed_at":"2023-03-04T21:06:00.000Z","size":431,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-03-05T03:25:19.861Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChristopherHX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-24T13:46:02.000Z","updated_at":"2023-03-05T03:25:19.861Z","dependencies_parsed_at":"2024-10-25T19:58:45.820Z","dependency_job_id":"ebb9e8e5-7a64-4df6-8443-f6f59fb94a5d","html_url":"https://github.com/ChristopherHX/libjnivm","commit_stats":null,"previous_names":[],"tags_count":4,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristopherHX%2Flibjnivm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristopherHX%2Flibjnivm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristopherHX%2Flibjnivm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristopherHX%2Flibjnivm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChristopherHX","download_url":"https://codeload.github.com/ChristopherHX/libjnivm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252770040,"owners_count":21801463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-25T15:39:06.732Z","updated_at":"2025-05-06T21:22:54.437Z","avatar_url":"https://github.com/ChristopherHX.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libjnivm\nPseudo Java Native Interface implement Java functions in C++\n\n## Dependencies\nOnly the c++14 or c++17 standard library. To run Unit Tests this project automatically downloads Google Test during configuration of cmake.\n\n## Building\nYou need g++, clang++ or msvc with at least c++14 support and cmake to build and use it.\n\n### Get the Source\n```\ngit clone https://github.com/ChristopherHX/libjnivm.git\ncd libjnivm\n```\n### Configure\nChoose zero or more configuration options to change the behaviour of this library.\n|CMake Option|Values|Default|Description|\n---|---|---|---\n|`JNIVM_ENABLE_TRACE`|`ON`, `OFF`|`OFF`|activate logging of called function to help Troubleshooting errors|\n|`JNIVM_ENABLE_GC`|`ON`, `OFF`|`ON`|deprecated option, previous version had only a experimental GC used to disable it enitirely|\n|`JNIVM_ENABLE_DEBUG`|`ON`, `OFF`|`ON`|enables additional debugging features like a stub code generator for faster reverse engineering. Use together with `void jnivm::VM::GenerateClassDump(const char * path);` to generate the stubs to a file (c++) with the specified path, you may need to create the parent folder of the path. You will get different generated code if you change the value of the configuration option `JNIVM_USE_FAKE_JNI_CODEGEN`|\n|`JNIVM_USE_FAKE_JNI_CODEGEN`|`ON`, `OFF`|`OFF`|choose to generate FakeJni compatible stubs instead of the default syntax of this library. Depends on `JNIVM_ENABLE_DEBUG=ON` to work. Use together with `Baron::Jvm::printStatistics()` to print the stubs to stdout|\n|`JNIVM_ENABLE_RETURN_NON_ZERO`|`ON`, `OFF`|`OFF`|contruct objects which are default_contructible with a parameterless contructor or classes without a native type as an empty jnivm::Object and returns these instead of returning a nullptr. Use together with `JNIVM_ENABLE_TRACE=ON`, to see if a method wasn't found, but a return value was constructed|\n|`JNIVM_FAKE_JNI_MINECRAFT_LINUX_COMPAT`|`ON`, `OFF`|`OFF`|It is unclear how the fake-jni interface should handle static functions and static fields, based on the original sample from https://github.com/dukeify/fake-jni/blob/16b82688cb9a8794580293253fbe313f550eb00c/examples/src/main.cpp it seems, it should promote them to instance functions. To intercept this behavior add `JNIVM_FAKE_JNI_MINECRAFT_LINUX_COMPAT=ON`, to keep them static if they are not explicitly set to static like `{ Function\u003c\u0026staticFunction\u003e, \"staticFunction\", JMethodID::Static }`|\n|`JNIVM_ENABLE_TESTS`|`ON`, `OFF`|`OFF`|enables and build gtest tests|\n|`JNIVM_BUILD_EXAMPLES`|`ON`, `OFF`|`OFF`|Enable jnivm / fake-jni (compat) examples|\n\ncreate and change to a build directory\n```\nmkdir build\ncd build\n```\nAdd the configure options like `-D\u003cOption\u003e=\u003cvalue\u003e` per option, add a space between each one. Then place them after `cmake .. `. For example two options shown here:\n```\ncmake .. -DJNIVM_ENABLE_TRACE=ON -DJNIVM_BUILD_EXAMPLES=ON\n```\n\nNow build the library and optionally it's Example and / or Tests\n```\ncmake --build .\n```\n\n## Fake-jni / Baron Compatibility\n\nProbably not all features of Fake-jni / Baron are implemented right now, open an issue to increase the chance to improve the compatibility.\nAs of 3.2021 the original has some broken features, they will close all issues without notice.\n- `FakeJni::JString` provided in this implementation correctly handles modified utf8 to utf16 like the Java native interface specification requires, but the original fake-jni has a strange things going on see here https://github.com/dukeify/fake-jni/issues/105\n- `FakeJni::Array\u003cT\u003e` (`T` is a FakeJni Class) has a similiar class hirachy as the type T\n    - So you can write `std::shared_ptr\u003cFakeJni::Array\u003cBase\u003e\u003e b = std::make_shared\u003cFakeJni::Array\u003cDerived\u003e\u003e();` without hitting undefined behavior or compile time errors, if `Derived` has the super class `Base` and you passed the type into the `DEFINE_CLASS_NAME(\"Derived\", Base)` macro\n- This implementation does not aim to provide a jvmti implementation at all, original FakeJni has only stubs as of 3.2021\n- This implementation has a Garbage collector based on `std::shared_ptr`, all object have to be wrapped within one, if they aren't a jni type\n  - You write `std::shared_ptr\u003cFakeJni::JObject\u003e obj;` instead of something like `FakeJni::JObject * obj;` or `FakeJni::JObject obj;`\n  - For Arrays you only need to wrap the outer array, like `std::shared_ptr\u003cFakeJni::Array\u003cFakeJni::JString\u003e\u003e` for a array of strings\n  - Multi dimension Arrays are defined like `std::shared_ptr\u003cFakeJni::Array\u003cFakeJni::Array\u003cFakeJni::JString\u003e\u003e\u003e`\n  - This is the same syntax as the changes to original FakeJni by [minecraft-linux](https://github.com/minecraft-linux/fake-jni)\n- FakeJni sometimes fabricates Object's instead of returning 0, to mimic this add `-DJNIVM_ENABLE_RETURN_NON_ZERO=ON`\n- Add `-DJNIVM_ENABLE_RETURN_NON_ZERO=ON`, `-DJNIVM_FAKE_JNI_MINECRAFT_LINUX_COMPAT=ON` to share your source code between [minecraft-linux](https://github.com/minecraft-linux/fake-jni) and this implementation\n- The samples of [Baron's Readme](https://github.com/dukeify/baron) will compile with this implementation\n  - We provide `void Baron::Jvm::printStatistics()` while the original doesn't even declare it\n\n## Examples\nYou find some examples inside `src/examples`. Please open one or more issue's if you have any additional questions or found a Bug not covered by a Test.\n\n## Similar Open Source Projects\n- https://github.com/minecraft-linux/fake-jni + https://github.com/minecraft-linux/baron\n- https://github.com/dukeify/fake-jni + https://github.com/dukeify/baron **Unmaintained since 4 Apr 2020**\n\n## History\n- Initially developed for https://github.com/ChristopherHX/mcpelauncher-manifest, fall 2019\n- Now optionally used by https://github.com/minecraft-linux/mcpelauncher-manifest/tree/ng to replace https://github.com/minecraft-linux/baron, fall 2020\n- Version 1.0 spring 2021\n    - Increased Test Line Coverage to ca. 70%\n    - Increased FakeJni / Baron compatibility\n    - Fixed String conversions, correctly handle and use Modified UTF8 \n    - Implemented a lot of missing things\n      - exception handling\n      - WeakGlobal's\n      - distinguish Global from Local References\n    - Removed unsafe type casts, a jobject is now always `jnivm::Object*` then casted via dynamic_cast to the right type","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristopherhx%2Flibjnivm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristopherhx%2Flibjnivm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristopherhx%2Flibjnivm/lists"}