J2TS Runtime
raw JSON → 92.0.0 verified Fri May 01 auth: no javascript
Runtime library required for code transpiled by the Java2TypeScript (J2TS) transpiler. Stable version 92.0.0 provides a set of Java-like utilities (e.g., ArrayList, HashMap) for TypeScript/JavaScript environments. Release cadence is tied to the J2TS transpiler. Key differentiator: enables running Java-derived code directly on Node.js or in browsers with minimal overhead. Only use as a dependency for J2TS projects.
Common errors
error Cannot find module 'j2ts-jre' ↓
cause Package not installed or missing from package.json.
fix
Run 'npm install j2ts-jre'
error TypeError: ArrayList is not a constructor ↓
cause Incorrect import pattern (e.g., default import instead of named import).
fix
Use 'import { ArrayList } from 'j2ts-jre''
error Module not found: Error: Can't resolve 'j2ts-jre/src/ArrayList' ↓
cause Deep importing internal modules instead of using the main export.
fix
Import from the package root: 'import { ArrayList } from 'j2ts-jre''
Warnings
gotcha Package is a runtime dependency for J2TS transpiled code. Do not manually add unless you are using the J2TS transpiler. ↓
fix Follow J2TS documentation for setup.
breaking Breaking changes occur frequently with major version bumps due to transpiler compatibility. See J2TS changelog. ↓
fix Upgrade both J2TS and j2ts-jre together.
deprecated Some Java methods may be deprecated in future versions. Check source for deprecation warnings. ↓
fix Use alternative methods as indicated in documentation.
Install
npm install j2ts-jre yarn add j2ts-jre pnpm add j2ts-jre Imports
- ArrayList wrong
const ArrayList = require('j2ts-jre').ArrayListcorrectimport { ArrayList } from 'j2ts-jre' - HashMap wrong
import HashMap from 'j2ts-jre'correctimport { HashMap } from 'j2ts-jre' - StringBuilder wrong
import { StringBuilder } from 'j2ts-jre/src/index'correctimport { StringBuilder } from 'j2ts-jre' - RuntimeExportedClass
import { RuntimeExportedClass } from 'j2ts-jre'
Quickstart
import { ArrayList } from 'j2ts-jre';
// Create an ArrayList and add elements
const list = new ArrayList<string>();
list.add('hello');
list.add('world');
console.log(list.size()); // 2
// Iterate
for (let i = 0; i < list.size(); i++) {
console.log(list.get(i));
}