# On windows if JAVA_HOME ends in a '\' then native launcher bombs

## Details

• Type: Bug
• Status: Resolved
• Priority: Blocker
• Resolution: Fixed
• Affects Version/s: JRuby 1.6.7
• Fix Version/s:
• Component/s:
• Labels:
None
• Number of attachments :
0

## Description

This is the reproduction:

```C:\Users\enebo>set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_23\

C:\Users\enebo>jruby -Xtrace trace.log -v
Exception in thread "main" java.lang.NoClassDefFoundError: bar
Caused by: java.lang.ClassNotFoundException: bar
at java.security.AccessController.doPrivileged(Native Method)
Could not find the main class: bar.  Program will exit.
```

And here is the trace.log:

```Starting platform...
Binary name is: jruby

Module: c:\jruby-1.6.7.1\bin\jruby.dll
Platform dir: c:\jruby-1.6.7.1
Parsing arguments:
-Xtrace
trace.log
-v
-Xjdkhome is not set, checking for %JAVA_HOME%...
%JAVA_HOME% is set: C:\Program Files\Java\jdk1.6.0_23\
JvmLauncher::initialize()
javaPathOrMinVersion: C:\Program Files\Java\jdk1.6.0_23\
checkJava(C:\Program Files\Java\jdk1.6.0_23\)
File "C:\Program Files\Java\jdk1.6.0_23\jre\bin\client\jvm.dll" does not exist
File "C:\Program Files\Java\jdk1.6.0_23\jre\bin\server\jvm.dll" exists
File "C:\Program Files\Java\jdk1.6.0_23\jre\bin\java.exe" exists
File "C:\Program Files\Java\jdk1.6.0_23\jre\bin\javaw.exe" exists
*** No need to clean the binary name: jruby
constructBootClassPath()
File "c:\jruby-1.6.7.1\lib\jruby.jar" exists
path: c:\jruby-1.6.7.1\lib\jruby.jar
onlyIfExists: true
File "c:\jruby-1.6.7.1\lib\jruby.jar" exists
File "c:\jruby-1.6.7.1\lib\jruby-complete.jar" does not exist
BootclassPath: c:\jruby-1.6.7.1\lib\jruby.jar
constructClassPath()
dir: c:\jruby-1.6.7.1
path: c:\jruby-1.6.7.1\lib\jruby.jar
onlyIfExists: false
No explicit classpath option is used, looking up %CLASSPATH% env
path: C:\foo bar bag\
onlyIfExists: false
ClassPath: C:\foo bar bag\;
JvmLauncher::getJavaPath()
Starting application...
JvmLauncher::start()
mainClassName: org/jruby/Main
separateProcess: false
args:
-v
options:
-Djdk.home=C:\Program Files\Java\jdk1.6.0_23\
-Djruby.home=c:\jruby-1.6.7.1
-Djruby.script=jruby
-Djruby.shell=cmd.exe
-Djffi.boot.library.path=c:\jruby-1.6.7.1\lib\native\i386-Windows;c:\jruby-1.6.7.1\lib\native\x86_64-Windows
-Xmx500m
-Xss2048k
-Djruby.memory.max=500m
-Djruby.stack.max=2048k
-Dsun.java.command=org.jruby.Main
-Djava.class.path=C:\foo bar bag\;
-Xbootclasspath/a:c:\jruby-1.6.7.1\lib\jruby.jar
Java DLL path: C:\Program Files\Java\jdk1.6.0_23\jre\bin\server\jvm.dll
PrepareDllPath: C:\Program Files\Java\jdk1.6.0_23\jre\bin
Falling back to running Java in a separate process; DLL cannot be loaded (64-bit DLL?).
Command line:
"C:\Program Files\Java\jdk1.6.0_23\jre\bin\java.exe" "-Djdk.home=C:\Program Files\Java\jdk1.6.0_23\" "-Djruby.home=c:\jruby-1.6.7.1" "-Djruby.script=jruby" "-Djruby.shell=cmd.exe" "-Djffi.boot.library.path=c:\jruby-1.6.7.1\lib\native\i386-Windows;c:\jruby-1.6.7.1\lib\native\x86_64-Windows" "-Xmx500m" "-Xss2048k" "-Djruby.memory.max=500m" "-Djruby.stack.max=2048k" "-Dsun.java.command=org.jruby.Main" "-Djava.class.path=C:\foo bar bag\;" "-Xbootclasspath/a:c:\jruby-1.6.7.1\lib\jruby.jar" org/jruby/Main "-v"
onExit()
```

Notice that -Djdk.home now ends in a '\"'. It looks like CMD will literalize this into a "?

## Activity

Hide
Hiro Asari added a comment -

Does it suffice to drop the backslash at the end of JAVA_HOME?

Show
Hiro Asari added a comment - Does it suffice to drop the backslash at the end of JAVA_HOME?
Hide
Hiro Asari added a comment -

An attempt to fix this is: https://github.com/jruby/jruby-launcher/commit/4aa28b279d37a9983d5fb6156428f347dcc7a625

In the commit above, we also trim trailing backslashes from JAVA_HOME on UNIX as well, just in case.

(I don't have a compiler on Windows set up, so I haven't tested the Windows part of the fix.)

Show
Hiro Asari added a comment - An attempt to fix this is: https://github.com/jruby/jruby-launcher/commit/4aa28b279d37a9983d5fb6156428f347dcc7a625 In the commit above, we also trim trailing backslashes from JAVA_HOME on UNIX as well, just in case. (I don't have a compiler on Windows set up, so I haven't tested the Windows part of the fix.)
Hide
Hiro Asari added a comment -

There are some remaining cases to be addressed on Windows:

`JAVA_HOME=D:\ `

Granted, it is a pathological case; perhaps we can stop trimming the trailing backslashes when the length reaches 3.

Show
Hiro Asari added a comment - There are some remaining cases to be addressed on Windows: JAVA_HOME=D:\ Granted, it is a pathological case; perhaps we can stop trimming the trailing backslashes when the length reaches 3.
Hide
Charles Oliver Nutter added a comment -

Hiro's fix seems reasonable to me, but I don't have Windows handy to test on.

Show
Charles Oliver Nutter added a comment - Hiro's fix seems reasonable to me, but I don't have Windows handy to test on.
Hide
Charles Oliver Nutter added a comment -

Looks like Hiro's fix is already in jruby-launcher, so mostly we just need to spin a new jruby-launcher release. Must do before RC2, for inclusion in Windows release.

Show
Charles Oliver Nutter added a comment - Looks like Hiro's fix is already in jruby-launcher, so mostly we just need to spin a new jruby-launcher release. Must do before RC2, for inclusion in Windows release.
Hide
Charles Oliver Nutter added a comment -

Ok, this was actually fixed in the 1.0.15 release of jruby-launcher, released before pre2.

Show
Charles Oliver Nutter added a comment - Ok, this was actually fixed in the 1.0.15 release of jruby-launcher, released before pre2.

## People

• Assignee:
Charles Oliver Nutter
Reporter:
Thomas E Enebo
0 Vote for this issue
Watchers:
3 Start watching this issue

## Dates

• Created:
Updated:
Resolved: