Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@objectx
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save objectx/e843854781e592a8ace1 to your computer and use it in GitHub Desktop.
Save objectx/e843854781e592a8ace1 to your computer and use it in GitHub Desktop.
[WIP] Start script for gradle's application plugin generated apps.
$FlagDebug = $true
$default_jvm_opts = ""
function debug {
if ($FlagDebug) {
Write-Host -foreground "yellow" $Args
}
}
function java_not_found {
Write-Error @"
JAVA_HOME is set to an invalid directory: $java_home
Please set the JAVA_HOME variable in your environment
to match the location of your Java installation.
"@
exit 1
}
function find_java {
if ($env:JAVA_HOME) {
$java = Get-Command -ErrorAction SilentlyContinue $(Join-Path $env:JAVA_HOME "bin/java.exe")
if ($java) {
debug "Found java via JAVA_HOME"
return $java
}
}
else {
$java = Get-Command "java.exe" -ErrorAction SilentlyContinue
if ($java) {
debug "Found java via PATH"
return $java
}
}
# Looking into the registry
foreach ($k in @('Java Development Kit', 'Java Runtime Environment')) {
$key = Join-Path 'HKLM:\SOFTWARE\JavaSoft' $k
if (-not $(Test-Path $key)) {
continue
}
$current = $(Get-Item $key).GetValue('CurrentVersion')
if (-not $current) {
continue
}
$java_home = $(Get-Item $(Join-Path $key $current)).GetValue('JavaHome')
if ($java_home) {
$java = Get-Command -ErrorAction SilentlyContinue $(Join-Path $java_home "bin/java.exe")
if ($java) {
debug "Found java via registry ($key)"
return $java
}
}
}
return $null
}
$app_home = Split-Path -parent $PSScriptRoot
# $app_base_name = Split-Path -leaf $PSCommandPath
# debug "app_base = ${app_base_name}, app_home = ${app_home}"
$java_exe = find_java
if (-not $java_exe) {
java_not_found
}
$classpath = ""
& $java_exe $default_jvm_opts $env:JVM_OPTS $env:FOOAPP_OPTS -classpath $classpath Main $Args
exit $LASTEXITCODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment