@@ -78,12 +78,19 @@ The latter two commands should return something like:
7878
7979> /usr/lib/jvm/java-11-openjdk-amd64/lib
8080
81+ ## Extra Features
82+
83+ * `locate-jdk-only`: Attempts to locate the JDK by searching for the Java compiler,
84+ as opposed to searching for the runtime.
85+ This solves issues in JDK 8 where the JRE resides in a subdirectory and not in the JDK root,
86+ so development files are not found in JAVA_HOME as would be expected.
87+
8188## License
8289
8390At your option, under:
8491
85- * Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0)
86- * MIT license (http://opensource.org/licenses/MIT)
92+ * Apache License, Version 2.0, (< http://www.apache.org/licenses/LICENSE-2.0> )
93+ * MIT license (< http://opensource.org/licenses/MIT> )
8794
8895 */
8996
@@ -96,6 +103,11 @@ use glob::{glob, Pattern};
96103
97104pub mod errors;
98105
106+ #[ cfg( not( feature = "locate-jdk-only" ) ) ]
107+ const LOCATE_BINARY : & str = "java" ;
108+ #[ cfg( feature = "locate-jdk-only" ) ]
109+ const LOCATE_BINARY : & str = "javac" ;
110+
99111/// Returns the name of the jvm dynamic library:
100112///
101113/// * libjvm.so for Linux
@@ -129,7 +141,7 @@ pub fn locate_java_home() -> Result<String> {
129141#[ cfg( target_os = "windows" ) ]
130142fn do_locate_java_home ( ) -> Result < String > {
131143 let output = Command :: new ( "where" )
132- . arg ( "java" )
144+ . arg ( LOCATE_BINARY )
133145 . output ( )
134146 . map_err ( |e| JavaLocatorError :: new ( format ! ( "Failed to run command `where` ({e})" ) ) ) ?;
135147
@@ -184,7 +196,7 @@ fn do_locate_java_home() -> Result<String> {
184196#[ cfg( not( any( target_os = "windows" , target_os = "macos" ) ) ) ] // Unix
185197fn do_locate_java_home ( ) -> Result < String > {
186198 let output = Command :: new ( "which" )
187- . arg ( "java" )
199+ . arg ( LOCATE_BINARY )
188200 . output ( )
189201 . map_err ( |e| JavaLocatorError :: new ( format ! ( "Failed to run command `which` ({e})" ) ) ) ?;
190202 let java_exec_path = std:: str:: from_utf8 ( & output. stdout ) ?. trim ( ) ;
@@ -276,4 +288,13 @@ mod unit_tests {
276288 fn locate_java_from_exec_test ( ) {
277289 println ! ( "do_locate_java_home: {}" , do_locate_java_home( ) . unwrap( ) ) ;
278290 }
291+
292+ #[ test]
293+ fn jni_headers_test ( ) {
294+ let java_home = do_locate_java_home ( ) . unwrap ( ) ;
295+ assert ! ( PathBuf :: from( java_home)
296+ . join( "include" )
297+ . join( "jni.h" )
298+ . exists( ) ) ;
299+ }
279300}
0 commit comments