Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

java

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

java - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

examples/lucene/lucene-analyzers-common-7.4.0.jar

8

examples/lucene/example.js
#!/usr/bin/env node
var java = require("../../");
java.classpath.push("lucene-core-6.0.0.jar");
java.classpath.push("lucene-analyzers-common-6.0.0.jar");
java.classpath.push("lucene-queryparser-6.0.0.jar");
java.classpath.push("./lucene-lib/lucene-core-7.4.0.jar");
java.classpath.push("./lucene-lib/lucene-analyzers-common-7.4.0.jar");
java.classpath.push("./lucene-lib/lucene-queryparser-7.4.0.jar");

@@ -13,3 +13,3 @@

var writer = java.newInstanceSync("org.apache.lucene.index.IndexWriter", idx, writerConfig);
var queryParser = java.newInstanceSync("org.apache.lucene.queryparser.analyzing.AnalyzingQueryParser", "content", analyzer);
var queryParser = java.newInstanceSync("org.apache.lucene.queryparser.classic.QueryParser", "content", analyzer);

@@ -16,0 +16,0 @@ writer.addDocumentSync(createDocument("Theodore Roosevelt",

@@ -10,5 +10,5 @@ {

],
"version": "0.10.0",
"version": "0.11.0",
"engines": {
"node": ">=0.10.0"
"node": ">=7.0.0"
},

@@ -30,11 +30,11 @@ "maintainers": [

"dependencies": {
"async": "2.6.0",
"async": "2.6.1",
"find-java-home": "0.2.0",
"glob": "7.1.2",
"lodash": "4.17.5",
"nan": "2.9.2"
"glob": "7.1.3",
"lodash": "4.17.11",
"nan": "2.11.1"
},
"devDependencies": {
"chalk": "2.1.0",
"nodeunit": "0.11.1",
"chalk": "2.4.1",
"nodeunit": "0.11.3",
"when": "3.7.8"

@@ -41,0 +41,0 @@ },

@@ -11,3 +11,3 @@ [![Build Status](https://travis-ci.org/joeferner/node-java.svg?branch=master)](https://travis-ci.org/joeferner/node-java)

* [node-java-maven](https://github.com/joeferner/node-java-maven) - manages your node-java classpath by using maven dependency mangement.
* [node-java-maven](https://github.com/joeferner/node-java-maven) - manages your node-java classpath by using maven dependency management.

@@ -46,2 +46,8 @@ ## Installation

Alternatively, Windows users can easily install all required tools by running the following command in PowerShell as administrator. For more information see [windows-build-tools project page](https://github.com/felixrieseberg/windows-build-tools):
```sh
npm install --global --production windows-build-tools
```
### Installation ARM (Raspberry Pi)

@@ -234,5 +240,7 @@

<a name="asyncOptionsDetails" >
### AsyncOptions: control over the generation of sync, async & promise method variants.
As of release 0.4.5 it became possible to create async methods that return promises by setting the asyncOptions property of the java object. With release 0.4.7 this feature is extended to allow changing the suffix assigned for sync and async method variants, and to further configure this module to optionally omit generation of any of these variants.
As of release 0.4.5 it became possible to create async methods that return promises by setting the `asyncOptions` property of the java object. With release 0.4.7 this feature is extended to allow changing the suffix assigned for sync and async method variants, and to further configure this module to optionally omit generation of any of these variants.

@@ -247,3 +255,3 @@ Example:

promiseSuffix: "Promise", // Generate methods returning promises, using the suffix Promise.
promisify: require("when/node").lift
promisify: require('util').promisify // Needs Node.js version 8 or greater, see comment below
};

@@ -262,5 +270,7 @@ java.classpath.push("commons-lang3-3.1.jar");

#### NOTES:
* If you want the defacto standard behavior, simply don't set java.asyncOptions.
* If you do provide asyncOptions, be aware that this module will not generate method variants of a given flavor if you don't provide a string value for the corresponding suffix (`asyncSuffix`, `syncSuffix`, `promiseSuffix`). In the example above, the application is configured to omit the method variants using node-style async callback functions.
* If you provide `asyncOptions.promiseSuffix` then you must also set `asyncOptions.promisify` to a function that *promisifies* a node-style async function. I.e. the provided function must take as input a function whose last argument is a node callback function, and it must return an equivalent promise-returning function. Several Promises/A+ libraries provide such functions, but it may be necessary to provide a wrapper function. See `testHelpers.js` for an example.
* For `promisify` implementation, if you are using Node.js version 8.0.0 or newer then `promisify: require('util').promisify` will work out of the box. If you need to support and older Node.js version then an implementation needs to be provided, for example, `promisify: require("when/node").lift`
* If you provide `asyncOptions.promisify` then you must provide a *non-empty* string for `asyncOptions.promiseSuffix`.

@@ -272,11 +282,9 @@ * Either (but not both) `asyncSuffix` or `syncSuffix` can be the empty string. If you want the defacto standard behavior for no suffix on async methods, you must provide an empty string for `asyncSuffix`.

##### Special note about the exported module functions `newInstance`, `callMethod`, and `callStaticMethod`.
These methods come in both async and sync variants. If you provide the `promisify` and `promiseSuffix` attributes in asyncOptions then you'll also get the Promises/A+ variant for these three functions. However, if you change the defacto
conventions for the `syncSuffix` (i.e. 'Sync') and/or `asyncSuffix` (i.e. '') it will not affect the naming for these three functions. I.e. no matter what you specify in asyncOptions, the async variants are named `newInstance`, `callMethod`, and `callStaticMethod`, and the sync variants are named `newInstanceSync`, `callMethodSync`, and `callStaticMethodSync`.
These methods come in both async and sync variants. If you provide the `promisify` and `promiseSuffix` attributes in asyncOptions then you'll also get the Promises/A+ variant for these three functions. However, if you change the defacto conventions for the `syncSuffix` (i.e. 'Sync') and/or `asyncSuffix` (i.e. '') it will not affect the naming for these three functions. I.e. no matter what you specify in asyncOptions, the async variants are named `newInstance`, `callMethod`, and `callStaticMethod`, and the sync variants are named `newInstanceSync`, `callMethodSync`, and `callStaticMethodSync`.
## Varargs support
With v0.5.0 node-java now supports methods with variadic arguments (varargs). Prior to v0.5.0,
a javascript call to a Java varargs method had to construct an array of the variadic arguments using `java.newArray()`. With v0.5.0 javascript applications can simply use the variadic style.
With v0.5.0 node-java now supports methods with variadic arguments (varargs). Prior to v0.5.0, a JavaScript call to a Java varargs method had to construct an array of the variadic arguments using `java.newArray()`. With v0.5.0 JavaScript applications can simply use the variadic style.
In most cases it is still acceptable to use `java.newArray()`. But it is now possible to pass a plain javascript array, or use the variadic style. For example, consider these snippets from the unit test file `test/varargs-test.js`:
In most cases it is still acceptable to use `java.newArray()`. But it is now possible to pass a plain JavaScript array, or use the variadic style. For example, consider these snippets from the unit test file `test/varargs-test.js`:

@@ -290,3 +298,3 @@ ```

Note that when passing a Javascript array (e.g. `['a', 'b', 'c']`) for a varargs parameter, node-java must infer the Java type of the array. If all of the elements are of the same javascript primitive type (`string` in this example) then node-java will create a Java array of the corresponding type (e.g. `java.lang.String`). The Java types that node-java can infer are: `java.lang.String`, `java.lang.Boolean`, `java.lang.Integer`, `java.lang.Long`, and `java.lang.Double`. If an array has a mix of `Integer`, `Long`, and `Double`, then the inferred type will be `java.lang.Number`. Any other mix will result in an inferred type of `java.lang.Object`.
Note that when passing a JavaScript array (e.g. `['a', 'b', 'c']`) for a varargs parameter, node-java must infer the Java type of the array. If all of the elements are of the same JavaScript primitive type (`string` in this example) then node-java will create a Java array of the corresponding type (e.g. `java.lang.String`). The Java types that node-java can infer are: `java.lang.String`, `java.lang.Boolean`, `java.lang.Integer`, `java.lang.Long`, and `java.lang.Double`. If an array has a mix of `Integer`, `Long`, and `Double`, then the inferred type will be `java.lang.Number`. Any other mix will result in an inferred type of `java.lang.Object`.

@@ -316,2 +324,3 @@ Methods accepting varargs of a generic type are also problematic. You will need to fall back to using `java.newArray()`. See [Issue #285](https://github.com/joeferner/node-java/issues/285).

* [options](#javaOptions)
* [asyncOptions](#javaAsyncOptions)
* [import](#javaImport)

@@ -349,2 +358,4 @@ * [newInstance](#javaNewInstance)

## classpath
*java.classpath**

@@ -361,2 +372,4 @@

## options
<a name="javaOptions" >

@@ -375,2 +388,24 @@

## asyncOptions
```javascript
java.asyncOptions = {
asyncSuffix: undefined, // Don't generate node-style methods taking callbacks
syncSuffix: "", // Sync methods use the base name(!!)
promiseSuffix: "Promise", // Generate methods returning promises, using the suffix Promise.
promisify: require('util').promisify // Needs Node.js version 8 or greater, see comment below
ifReadOnlySuffix: "_alt"
};
```
* `asyncSuffix` Suffix for callback-based async method call signatures.
* `syncSuffix` Suffix for synchronous method call signatures.
* `promiseSuffix` Suffix for promise-based async method call signatures
* `promisify` Callback-to-promise transform implementation. From Node.js version 8 one can just use Node.js implementation: `promisify: require('util').promisify`.
* `ifReadOnlySuffix` See [Static Member Name Conflicts](#staticMemberNameConflicts).
See [Async Options](#asyncOptionsDetails) for details.
## import
<a name="javaImport" >

@@ -380,7 +415,7 @@

Loads the class given by className such that it acts and feels like a javascript object.
Loads the class given by className such that it acts and feels like a JavaScript object.
__Arguments__
* className - The name of the class to create. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
* className - The name of the class to create. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).

@@ -398,2 +433,4 @@ __Example__

## newInstance
<a name="javaNewInstance" >

@@ -405,3 +442,3 @@

Creates an instance of the specified class. If you are using the sync method an exception will be throw if an error occures,
Creates an instance of the specified class. If you are using the sync method an exception will be throw if an error occurs,
otherwise it will be the first argument in the callback.

@@ -411,3 +448,3 @@

* className - The name of the class to create. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
* className - The name of the class to create. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
* callback(err, item) - Callback to be called when the class is created.

@@ -424,2 +461,4 @@

## instanceOf
<a name="javaInstanceOf" >

@@ -444,2 +483,4 @@

## callStaticMethod
<a name="javaCallStaticMethod" >

@@ -451,3 +492,3 @@

Calls a static method on the specified class. If you are using the sync method an exception will be throw if an error occures,
Calls a static method on the specified class. If you are using the sync method an exception will be throw if an error occurs,
otherwise it will be the first argument in the callback.

@@ -457,3 +498,3 @@

* className - The name of the class to call the method on. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
* className - The name of the class to call the method on. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
* methodName - The name of the method to call. The method name can include the full signature (see [Getting the full method signature](#getFullMethodSignature)).

@@ -471,2 +512,4 @@ * callback(err, item) - Callback to be called when the class is created.

## callMethod
<a name="javaCallMethod" >

@@ -478,3 +521,3 @@

Calls a method on the specified instance. If you are using the sync method an exception will be throw if an error occures,
Calls a method on the specified instance. If you are using the sync method an exception will be throw if an error occurs,
otherwise it will be the first argument in the callback.

@@ -499,2 +542,4 @@

## getStaticFieldValue
<a name="javaGetStaticFieldValue" >

@@ -508,3 +553,3 @@

* className - The name of the class to get the value from. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
* className - The name of the class to get the value from. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
* fieldName - The name of the field to get the value from.

@@ -516,2 +561,4 @@

## setStaticFieldValue
<a name="javaSetStaticFieldValue" >

@@ -525,3 +572,3 @@

* className - The name of the class to set the value on. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
* className - The name of the class to set the value on. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
* fieldName - The name of the field to set the value on.

@@ -534,2 +581,4 @@ * newValue - The new value to assign to the field.

## newArray
<a name="javaNewArray" >

@@ -539,8 +588,8 @@

Creates a new java array of type class.
Creates a new java array of given glass type. To create array of primitive types like `char`, `byte`, etc, pass the primitive type name (eg. `java.newArray("char", "hello world\n".split(''))`).
__Arguments__
* className - The name of the type of array elements. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
* values - A javascript array of values to assign to the java array.
* className - The name of the type of array elements. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
* values - A JavaScript array of values to assign to the java array.

@@ -551,2 +600,4 @@ __Example__

## newByte
<a name="javaNewByte" >

@@ -556,3 +607,3 @@

Creates a new java byte. This is needed because javascript does not have the concept of a byte.
Creates a new java byte. This is needed because JavaScript does not have the concept of a byte.

@@ -567,2 +618,4 @@ __Arguments__

## newShort
<a name="javaNewShort" >

@@ -572,3 +625,3 @@

Creates a new java short. This is needed because javascript does not have the concept of a short.
Creates a new java short. This is needed because JavaScript does not have the concept of a short.

@@ -583,2 +636,4 @@ __Arguments__

## newLong
<a name="javaNewLong" >

@@ -588,3 +643,3 @@

Creates a new java long. This is needed because javascript does not have the concept of a long.
Creates a new java long. This is needed because JavaScript does not have the concept of a long.

@@ -599,2 +654,4 @@ __Arguments__

## newChar
<a name="javaNewChar" >

@@ -604,3 +661,3 @@

Creates a new java char. This is needed because javascript does not have the concept of a char.
Creates a new java char. This is needed because JavaScript does not have the concept of a char.

@@ -615,2 +672,4 @@ __Arguments__

## newDouble
<a name="javaNewDouble" >

@@ -620,3 +679,3 @@

Creates a new java double. This is needed to force javascript's number to a double to call some methods.
Creates a new java double. This is needed to force JavaScript's number to a double to call some methods.

@@ -631,2 +690,4 @@ __Arguments__

## newFloat
<a name="javaNewFloat" >

@@ -636,3 +697,3 @@

Creates a new java float. This is needed to force javascript's number to a float to call some methods.
Creates a new java float. This is needed to force JavaScript's number to a float to call some methods.

@@ -647,2 +708,4 @@ __Arguments__

## newProxy
<a name="javaNewProxy" >

@@ -659,3 +722,3 @@

* interfaceName - The name of the interface to proxy. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
* interfaceName - The name of the interface to proxy. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
* functions - A hash of functions matching the function in the interface.

@@ -675,2 +738,4 @@

## isJvmCreated
<a name="javaisJvmCreated" >

@@ -682,2 +747,4 @@

## registerClient
<a name="javaRegisterClient" >

@@ -689,2 +756,4 @@

## registerClientP
<a name="javaRegisterClientP" >

@@ -696,2 +765,4 @@

## ensureJvm
<a name="javaEnsureJvm" >

@@ -707,4 +778,6 @@

# java object
# `java` object
## Call Method
<a name="javaObjectCallMethod" >

@@ -732,2 +805,4 @@

## Field Access
<a name="javaObjectGetSetField" >

@@ -748,6 +823,6 @@

## Getting the Full Method Signature
<a name="getFullMethodSignature" >
Getting the Full Method Signature
Run `javap -s -classpath <your-class-path> <your-class-name>`. Find the method name you are looking for. For example:

@@ -815,6 +890,9 @@

# Static member name conficts ('name', 'arguments', 'caller')
The Javscript object returned by `java.import(classname)` is a Javascript constructor Function, implemented such that you can create instances of the Java class. For example:
<a name="staticMemberNameConflicts" >
# Static member name conflicts ('name', 'arguments', 'caller')
The JavaScript object returned by `java.import(classname)` is a JavaScript constructor Function, implemented such that you can create instances of the Java class. For example:
```javascript

@@ -829,3 +907,3 @@ var Test = java.import('Test');

But Javascript reserves a few property names of Function objects: `name`, `arguments`, and `caller`. If your class has public static members (either methods or fields) with these names, node-java is unable to create the necessary property to implement the class's API. For example, suppose your class `Test` implements a static method named `caller`, or has a `NestedEnum` with a value `name`:
But JavaScript reserves a few property names of Function objects: `name`, `arguments`, and `caller`. If your class has public static members (either methods or fields) with these names, node-java is unable to create the necessary property to implement the class's API. For example, suppose your class `Test` implements a static method named `caller`, or has a `NestedEnum` with a value `name`:

@@ -840,3 +918,3 @@ ```java

In Javascript, you would expect to be able to use those static members like this:
In JavaScript, you would expect to be able to use those static members like this:

@@ -849,3 +927,3 @@ ```javascript

Node-java can't create those properties, so the above code won't work. Instead, node-java appends a suffix to the name. The default suffix is simpy an underscore `_`, but you can change the suffix using asyncOptions:
Node-java can't create those properties, so the above code won't work. Instead, node-java appends a suffix to the name. The default suffix is simply an underscore `_`, but you can change the suffix using `asyncOptions`:

@@ -870,3 +948,3 @@ ```javascript

Either postInstall.js didn't run or there was a problem detecting java. Try running postInstall.js manually.
Either `postInstall.js` didn't run or there was a problem detecting java. Try running `postInstall.js` manually.

@@ -873,0 +951,0 @@ ## Debugging

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc