Skip to content

kylestev/jvm.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Oct 8, 2019
c6e0174 · Oct 8, 2019
Sep 22, 2018
Oct 7, 2019
Dec 2, 2015
Sep 22, 2018
Nov 9, 2015
Nov 6, 2015
Nov 7, 2015
Sep 22, 2018
Oct 30, 2015
Sep 22, 2018
Oct 8, 2019
May 19, 2019

Repository files navigation

jvm.js

A bytecode library for Java written in Node.js

npm version

This module is under active development and has not yet reached a stable release. This module will be following SemVer once it is ready for use by 3rd parties.


Installation

$ npm install jvm

And you will be able to get started with using jvm.js. Take a look at the next section for some examples of how to get started.

Examples

jvm.js makes use of Promises instead of passing callbacks in functions. This allows your code to not fall victim to the node callback tree of doom. You'll see examples of it in the examples below.

If you're unfamiliar with Promises, or need a refresher, checkout Mozilla's excellent documentation here.

Loading a Jar's classes

The example below uses ES6 and shows how easy it is to parse a Jar file.

import { Jar } from 'jvm';

Jar.unpack('./test.jar')
  .then((jar) => {
    for (let [name, cls] of jar) {
      if (cls.name === 'client') {
        console.log('found client class!');
        console.log(JSON.stringify({
          name: cls.name,
          superName: cls.superName,
          methodCount: cls.methods.length,
          fieldCount: cls.fields.length
        }, null, 2));
      }
    }
  })
  .catch(console.error.bind(console));