Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:29:50+00:00 2026-05-25T20:29:50+00:00

It seems most documentation or helper libraries relating to JNI (Java Native Interface) are

  • 0

It seems most documentation or helper libraries relating to JNI (Java Native Interface) are concerned with calling native code from Java. This seems to be the main use of it, even though it is capable of more.

I want to mostly work in the opposite direction: modify an existing (fairly large) portable C++ program by adding some Java libraries to it. For example, I want to make it call databases via JDBC, or message queue systems via JMS, or send emails, or call my own Java classes, etc. But with raw JNI this is pretty unpleasant and error-prone.

So I would ideally like to write C++ code that can call Java classes as easily as C++/CLI can call CLR classes. Something like:

using namespace java::util::regex; // namespaces mapped

Pattern p = Pattern.compile("[,\\s]+");

array<java::lang::String> result = 
    p.split("one,two, three   four ,  five");

for (int i=0; i < result.length(); i++)
    std::cout << result[i] << std::endl;

This way, I wouldn’t have to manually do the work of getting the method ID by passing the name and the weird signature strings, and would be protected from programming errors caused by the unchecked APIs for calling methods. In fact it would look a lot like the equivalent Java.

NB. I AM STILL TALKING ABOUT USING JNI! As an underlying technology it is perfect for my needs. It is “in process” and highly efficient. I don’t want to run Java in a separate process and make RPC calls to it. JNI itself is fine. I just want a pleasant interface to it.

There would have to be a code generation tool to make equivalent C++ classes, namespaces, methods, etc. to exactly match what is exposed by a set of Java classes I specify. The generated C++ classes would:

  • Have member functions that accept similarly-wrapped versions of their parameters and then do the necessary JNI voodoo to make the call.
  • Wrap the return values in the same way so I can chain calls in a natural way.
  • Maintain a per-class static cache of method IDs to avoid looking up them every time.
  • Be totally thread-safe, portable, open source.
  • Automatically check for exceptions after every method call and produce a std C++ exception.
  • Also work for when I’m writing native methods in the usual JNI way but I need to call on to other Java code.
  • The array should work totally consistently between primitive types and classes.
  • Will no doubt need something like global to wrap references in when they need to survive outside of a local reference frame – again, should work the same for all array/object references.

Does such a free, open-source, portable library/tool exist or am I dreaming?

Note: I found this existing question but the OP in that case wasn’t nearly as demanding of perfection as I am being…

Update: a comment about SWIG led me to this previous question, which seems to indicate that it is mostly about the opposite direction and so wouldn’t do what I want.

IMPORTANT

  • This is about being able to write C++ code that manipulates Java classes and objects, not the other way round (see the title!)
  • I already know that JNI exists (see the question!) But hand-written code to the JNI APIs is unnecessarily verbose, repetitious, error-prone, not type-checked at compile time, etc. If you want to cache method IDs and class objects it’s even more verbose. I want to automatically generate C++ wrapper classes that take care of all that for me.

Update: I’ve started working on my own solution:

https://github.com/danielearwicker/cppjvm

If this already exists, please let me know!

NB. If you’re considering using this in your own project, feel free, but bear in mind that right now the code is a few hours old, and I only wrote three very unstrenuous tests so far.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:29:51+00:00Added an answer on May 25, 2026 at 8:29 pm

    Yes, there are existing tools that do exactly this — generate C++ wrappers for Java classes. This makes use of Java APIs in C++ more transparent and enjoyable, with lower cost and risk.

    The one that I’ve used the most is JunC++ion. It’s mature, powerful and stable. The primary author is very nice, and very responsive. Unfortunately, it’s a commercial product, and pricey.

    Jace is a free, open-source tool with a BSD license. It’s been years since I last played with jace. Looks like there’s still some active development. (I still remember the USENET post by the original author, over a decade ago, asking basically the same question you’re asking.)

    If you need to support callbacks from Java to C++, it’s helpful to define C++ classes that implement Java interfaces. At least JunC++ion allows you to pass such C++ classes to Java methods that take callbacks. The last time I tried jace, it did not support this — but that was seven years ago.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most of Apples documentation seems to avoid using autoreleased objects especially when creating gui
Seems to me most of developers completely ignore this features. People prefer handling security
It seems like in most mainstream programming languages, returning multiple values from a function
I have recently downloaded the most recent build of this awesome tool WSDL2OBJC from
This seems like one of the most basic things that one might want to
Before I dive into ASIHttpRequest's source code: From the documentation ( http://allseeing-i.com/ASIHTTPRequest/How-to-use ) of
It seems most documentation recommends : template_values = {} template_values[foo] = bar return render_to_response(path,
In my experience most architectural documentation has been ad-hoc at best,and, aside from more
It seems that most of the installers for Perl are centered around installing Perl
It seems like most examples of JPA/Hibernate entity bean classes I've seen do no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.