diff --git a/nodejs-packages/jvm-launch-utils/package.json b/nodejs-packages/jvm-launch-utils/package.json index b3e33ebf2..9b33b0a42 100644 --- a/nodejs-packages/jvm-launch-utils/package.json +++ b/nodejs-packages/jvm-launch-utils/package.json @@ -1,12 +1,13 @@ { "name": "@pivotal-tools/jvm-launch-utils", - "version": "0.0.9", + "version": "0.0.10", "description": "Provides utilities useful for launching Java processes from node packages.", "files": [ "src", "lib" ], "main": "lib/index.js", + "types": "lib/index.d.ts", "scripts": { "prepare": "tsc -p .", "test": "echo \"Error: no test specified\" && exit 1" @@ -29,5 +30,8 @@ "devDependencies": { "@types/node": "^9.4.6", "typescript": "^2.7.2" + }, + "dependencies": { + "file-url": "^2.0.2" } } diff --git a/nodejs-packages/jvm-launch-utils/src/jvm-util.ts b/nodejs-packages/jvm-launch-utils/src/jvm-util.ts index 4c4736ad2..793b27bdc 100644 --- a/nodejs-packages/jvm-launch-utils/src/jvm-util.ts +++ b/nodejs-packages/jvm-launch-utils/src/jvm-util.ts @@ -2,6 +2,7 @@ import * as FS from 'fs'; import * as Path from 'path'; import * as ChildProcess from 'child_process'; import { basename } from 'path'; +import * as fileUrl from 'file-url'; 'use strict'; @@ -33,6 +34,14 @@ export interface JVM { * then this will return null. */ getToolsJar() : string | null + + /** + * Launch an executable jar with this jvm. + * This autmatically adds tools.jar to the classpath if available. + * WARNING: For adding tools jar to work properly, the jar must be packaged + * using spring-boot-maven-plugin ZIP layout. + */ + jarLaunch(jar: string, vmargs?: string[], execFileOptions?: ChildProcess.ExecFileOptions) : ChildProcess.ChildProcess } /** @@ -196,6 +205,18 @@ class JVMImpl implements JVM { getToolsJar(): string { return this.toolsJar(); } + jarLaunch(jar: string, vmargs?: [string], execFileOptions?: ChildProcess.ExecFileOptions): ChildProcess.ChildProcess { + let args = []; + let toolsJar = this.getToolsJar(); + if (toolsJar) { + args.push("-Dloader.path="+fileUrl(toolsJar)); + } + if (vmargs) { + args.push(...vmargs); + } + args.push("-jar", jar); + return ChildProcess.execFile(this.getJavaExecutable(), args, execFileOptions); + } } function getJavaInfo(javaExe : string) : Promise> { diff --git a/nodejs-packages/jvm-launch-utils/tsconfig.json b/nodejs-packages/jvm-launch-utils/tsconfig.json index a9c928a12..fabd5d06f 100644 --- a/nodejs-packages/jvm-launch-utils/tsconfig.json +++ b/nodejs-packages/jvm-launch-utils/tsconfig.json @@ -3,6 +3,7 @@ "target": "es6", "module": "commonjs", "outDir": "lib", - "sourceMap": true + "sourceMap": true, + "declaration": true } } \ No newline at end of file