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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jree

v1.3.0

Published

Java Runtime Environment Emulation

Downloads

898

Readme

Build & Test Downloads

Java Runtime Environment Emulation

This module contains a subset of JRE classes ported to Typescript and serves as runtime for Typescript and Javascript code that need JRE classes. It's a clean room implementation, which means no Java code was used for the implementation. Everything was written from scratch, but the Java API documentation was used as a reference. This allows to release the code under a permissive license (MIT) and to use it in any (including commercial) projects, in opposition to the GPL license of the original JRE.

It is not necessary to have Java installed, as the JREE runs purely in a Javascript interpreter (Node.js or a browser).

Installation and Use

Run

npm i jree

to install the package and then import the java root namespace from there. With that you can use a supported class via fully qualified names:

import { java } from "jree";

const builder = new java.lang.StringBuilder();
builder.append(123);

You can also import a class directly from full path, but I recommend to stay with fully qualified identifiers. In addition to the JRE classes there's' some support code that might come in handy. See the support readme for more details.

Testing and Examples

Unit Tests

Since the implementation is created solely from the Java API documentation it is important to have a good test coverage to ensure that the classes behave as expected. Therefore a number of JDK tests have been converted to Typescript and run as part of the test suite. The overall test coverage is currently at 43%. The tests are located in the test folder and can be run using npm run test or npm run test-coverage (the latter will also print a coverage report).

Examples

Additionally, there are some examples in the examples folder. They are modelled after common Java sample programs.

To run an example in a terminal you have to install ts-node globally:

npm i -g ts-node

Then you can run the example with

ts-node src/runner examples/HelloWorld

The HelloWorld demo is also executable using the NPM script "hello-world":

npm run hello-world

The runner script is a simple wrapper to load the given example (which must contain exactly one class with the typical main() method, and execute it. It can serve as a starting point for your own programs.

The examples do not use the the jree node package, but work directly with the source code in this project. However, it's easy to see how they would work with the installed module.

Supported Java Classes

The JRE emulation is still work-in-progress and contains a mix of either fully or partially converted Java classes. It's not planned to convert the entire JRE, but over time more and more classes may be added (pull requests welcome!).

See the Types List for the currently implemented classes and read the features description for additional details for usage of the JREE node package.

Environments

The JREE runs in both, Node.js and a browser. Certain classes use Node.js code currently (e.g. file system or path). The System class imports dependencies dynamically and fills its properties either from the browser environment or Node.js. The File class, however, cannot be used in a browser. Solve this by using a bundler like rollup.js or Webpack. That should tree-shake this class out or you can provide a shim for the used node package for the bundling process.

Development and Contribution

The development process used in this repo is pretty simple. There are a number NPM scripts for building, linting and testing the classes. Run npm run build to have typescript create the lib folder as it is used in the node module. Execute npm run test-coverage to run all unit tests and print some coverage info.

Adding new classes to this repository is described in more detail in How To Add.