Add a 'jarLaunch' methid JVM in jvm-utils
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Map<string, string>> {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"outDir": "lib",
|
||||
"sourceMap": true
|
||||
"sourceMap": true,
|
||||
"declaration": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user