npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jnipp.cxx

v1.2024.11

Published

C++ wrapper for the Java Native Interface; Mitchell Dowd (2016).

Downloads

11

Readme

Java Native Interface for C++

Overview

JNIPP is just a C++ wrapper for the standard Java Native Interface (JNI). It tries to take some of the long-winded annoyance out of integrating your Java and C++ code.

While this project has so far just been a utility library for my own usage, it seems to have caught the eye of some others who have also been looking for a suitable C++ JNI layer. If you have feature requests, do not hesitate to submit them as Github issues. Please be descriptive in your feature request. The more useful information you provide - along with justification on why it should be implemented - the more likely it is that I will add your feature.

Requirements

To compile you will need:

  • A C++11 compatible compiler
  • An installation of the Java Development Kit (JDK)
  • The JAVA_HOME environment variable, directed to your JDK installation.

Installation

Run:

$ npm i jnipp.cxx

And then include jnipp.h as follows:

// main.cxx
#include <jnipp.h>

int main() { /* ... */ }

Finally, compile while adding the path node_modules/jnipp.cxx to your compiler's include paths.

$ clang++ -std=c++17 -I./node_modules/jnipp.cxx main.cxx  # or, use g++
$ g++     -std=c++17 -I./node_modules/jnipp.cxx main.cxx

You may also use a simpler approach with the cpoach tool, which automatically adds the necessary include paths of all the installed dependencies for your project.

$ cpoach clang++ -std=c++17 main.cxx  # or, use g++
$ cpoach g++     -std=c++17 main.cxx

Usage

For comprehensive examples on how to use jnipp, see the tests project in the project source code.

There are two situations where the Java Native Interface would be needed.

  • A Java application calling C/C++ functions; or
  • A C/C++ application calling Java methods

Calling Java from C++

The following is an example of calling Java from C++.

#include <jnipp.h>

int main()
{
    // An instance of the Java VM needs to be created.
    jni::Vm vm;

    // Create an instance of java.lang.Integer
    jni::Class Integer = jni::Class("java/lang/Integer");
    jni::Object i = Integer.newInstance("1000");

    // Call the `toString` method on that integer
    std::string str = i.call<std::string>("toString");

    // The Java VM is automatically destroyed when it goes out of scope.
    return 0;
}

Calling C++ from Java

Consider a basic Java program:

package com.example;

class Demo {
    public int value;

    public static void main(String[] args) {
        Demo demo = new Demo();
        demo.value = 1000;
        demo.run();
    }

    public native void run();
}

A matching C++ library which uses jnipp could look like:

#include <jnipp.h>
#include <iostream>

/*
    The signature here is defind by the JNI standard, so must be adhered to.
    Although, to prevent pollution of the global namespace, the JNIEnv and
    jobject types defind by the standard JNI have been placed into the
    jni namespace.
 */
extern "C" void Java_com_example_Demo_run(jni::JNIEnv* env, jni::jobject obj)
{
    // jnipp only needs initialising once, but it doesn't hurt to do it again.
    jni::init(env);

    // Capture the supplied object.
    jni::Object demo(obj);

    // Print the contents of the `value` field to stdout.
    std::cout << demo.get<int>("value") << std::endl;
}

Configuration

By default, jnipp uses std::runtime_error as the base exception class. If you wish, you can define JNIPP_EXCEPTION_CLASS to be the exception class you wish to use, before including jnipp.h. It just needs a const char* constructor.

SRC ORG