Skip to content

Commit 947a032

Browse files
penbergnicksieger
authored andcommitted
Respect JAVACMD environment variable if it's set
This patch changes the launcher to respect the JAVACMD environment variable for determining JVM launcher command. Signed-off-by: Nick Sieger <[email protected]>
1 parent 4979a49 commit 947a032

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

spec/launcher_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
jruby_launcher("-Xhelp 2>&1").should =~ /JRuby Launcher usage/
1414
end
1515

16+
it "should use $JAVACMD when JAVACMD is specified" do
17+
with_environment "JAVACMD" => File.join("jato") do
18+
if windows?
19+
jruby_launcher_args("-v 2>&1").join.should =~ %r{jato}
20+
else
21+
jruby_launcher_args("-v").first.should == File.join("jato")
22+
end
23+
end
24+
end
25+
1626
it "should use $JAVA_HOME/bin/java when JAVA_HOME is specified" do
1727
with_environment "JAVA_HOME" => File.join("some", "java", "home") do
1828
if windows?

unixlauncher.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ int UnixLauncher::run(int argc, char* argv[], char* envp[]) {
3838

3939
string java("");
4040

41-
if (!jdkhome.empty()) {
42-
java = jdkhome + "/bin/java";
43-
} else if (getenv("JAVA_HOME") != NULL) {
44-
java = string(getenv("JAVA_HOME")) + "/bin/java";
41+
if (getenv("JAVACMD") != NULL) {
42+
java = getenv("JAVACMD");
4543
} else {
46-
java = findOnPath("java");
44+
if (!jdkhome.empty()) {
45+
java = jdkhome + "/bin/java";
46+
} else if (getenv("JAVA_HOME") != NULL) {
47+
java = string(getenv("JAVA_HOME")) + "/bin/java";
48+
} else {
49+
java = findOnPath("java");
50+
}
4751
}
4852

4953
if (java.empty()) {

0 commit comments

Comments
 (0)