8

When building JPostal I issued the command:

./gradlew assemble

I get the following error:

checking for gcj... no
checking for guavac... no
checking for jikes... no
checking for javac... no
configure: error: no acceptable Java compiler found in $PATH
make: *** No rule to make target 'install'.  Stop.
:buildJniLib FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildJniLib'.
> Process 'command 'sh'' finished with non-zero exit value 2

The problem is I've added the correct path to the java compiler to environmental variables. In fact when I type javac in CMD it shows all javac options as discussed in this SO answer. Typing javac -version for example in command line shows the correct version: javac 1.8.0_191

I have also set JAVA_HOME environmental variables as suggested in this thread.

Why isn't Java compiler being detected?

UPDATE 1:

The output of the three commands to see the current definition of local, user and system Path.

Local path:

set path

Path=C:\x\Java\jdk1.8.0_191\bin;C:\x\ProgramFiles\Firefox;C:\Windows\System32;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

User path:

reg query HKCU\Environment /v Path

ERROR: The system was unable to find the specified registry key or value.

System path:

reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v Path

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
    Path    REG_SZ    C:\x\Java\jdk1.8.0_191\bin;C:\x\ProgramFiles\Firefox;C:\Windows\System32;

After posting the information up to UPDATE 4 the System path was modified according to an advice with the Environment Variables control panel dialog window to:

%SystemRoot%\system32
%SystemRoot%
%SystemRoot%\System32\Wbem
%SystemRoot%\System32\WindowsPowerShell\v1.0\
%SystemRoot%\System32\OpenSSH\
C:\x\Java\jdk1.8.0_191\bin
C:\x\ProgramFiles\Firefox

Please see the screenshot of the system defined environmental variable for Path below:

Folder paths of system environment variable Path

Note: I didn't delete Firefox because it is required for internal reasons and I don't think it will effect the other variables defined.

UPDATE 2:

When I execute the command which java in MSYS2 window I get the following output:

which: no java in (/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)

I don't understand why it isn't detecting Java.

UPDATE 3:

When I execute the command where java in CMD I get the following:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\x\Java\jdk1.8.0_191\bin\java.exe

UPDATE 4:

In MSYS2 I issued the command:

export PATH=$PATH:"C:\x\Java\jdk1.8.0_191\bin"

and this seemed to solve the problem with javac:

checking for javac... javac
checking if javac works... yes
checking for C:\x\Java\jdk1.8.0_191/include/jni.h... yes

However, I still don't understand why it is not reading the environmental variables correctly.

Additionally, the build still fails due to:

checking for gcj... no
checking for guavac... no
checking for jikes... no
checking for javac... javac
checking if javac works... yes
checking for C:\x\Java\jdk1.8.0_191/include/jni.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for size_t... yes
checking for uint16_t... yes
checking for GNU libc compatible malloc... yes
checking for strdup... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for LIBPOSTAL... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/main/c/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
Making install in src/main/c
make[1]: Entering directory '/c/x/ProgramFiles/JPostal/src/main/c'
/bin/sh ../../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../..    -I/mingw64/include  -g -O2 -IC:\x\Java\jdk1.8.0_191/include -MT libjpostal_parser_la-jpostal_AddressParser.lo -MD -MP -MF .deps/libjpostal_parser_la-jpostal_AddressParser.Tpo -c -o libjpostal_parser_la-jpostal_AddressParser.lo `test -f 'jpostal_AddressParser.c' || echo './'`jpostal_AddressParser.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../.. -I/mingw64/include -g -O2 -IC:xJavajdk1.8.0_191/include -MT libjpostal_parser_la-jpostal_AddressParser.lo -MD -MP -MF .deps/libjpostal_parser_la-jpostal_AddressParser.Tpo -c jpostal_AddressParser.c  -DDLL_EXPORT -DPIC -o .libs/libjpostal_parser_la-jpostal_AddressParser.o
jpostal_AddressParser.c:1:10: fatal error: jni.h: No such file or directory
    1 | #include <jni.h>
      |          ^~~~~~~
compilation terminated.
make[1]: *** [Makefile:473: libjpostal_parser_la-jpostal_AddressParser.lo] Error 1
make[1]: Leaving directory '/c/x/ProgramFiles/JPostal/src/main/c'
make: *** [Makefile:404: install-recursive] Error 1

UPDATE 5:

See screenshot below showing the directory Java is installed in:

Contents of directory C:\x\Java\jdk1.8.0_191

UPDATE 6:

The screenshot below shows jni.h file present in Java installation folder:

Contents of directory C:\x\Java\jdk1.8.0_191\include

Mofi
  • 46,139
  • 17
  • 80
  • 143
Bradford Griggs
  • 439
  • 2
  • 15
  • Try and add the JAVA_HOME variable to the PATH variable then retry. According to error it is searching in PATH variable and not the JAVA_HOME. – Timsib Adnap Feb 23 '22 at 06:36
  • You mean set `Path` to `%JAVA_HOME%`? I did that and I also set `Path` directly to the JDK folder `/.../jdk1.8.0_191\jre\bin` and it didn't help.. – Bradford Griggs Feb 23 '22 at 06:41
  • RE: https://github.com/openvenues/jpostal/issues/21 – Erin Parkinson Feb 23 '22 at 07:18
  • @Mofi thank you for your keen insight and time. I was able to get the compiler to recognize the Java Compiler if I manually issue the command `export PATH=$PATH:/x/Java/jdk1.8.0_191/bin` (or `PATH=$PATH:"C:\xApps\Java\jdk1.8.0_191\bin"` - both seem to work!). You are probably right that some process must be overwriting the local copy of `Path` I guess what remains is to identify that process - why thr `local` instance of `Path` is being overwritten.. (cont) – Bradford Griggs Feb 24 '22 at 19:20
  • (cont) I'm not sure if this is related to the problem at hand but even after I manually `export` Java Compiler Path I get an identical error about [jni.h file missing](https://stackoverflow.com/questions/71245071/jpostal-build-fails-due-to-missing-jni-h-file). I tried to resolve this by issuing the command: `export JNI_INCLUDE_DIRS="C:\x\Java\jdk1.8.0_191\include"` but it doesn't seem to resolve the problem (i.e, I still get `fatal error: jni.h: No such file or directory 1 | #include `) (I updated the OP with screenshot showing the `jni.h` file) – Bradford Griggs Feb 24 '22 at 19:27
  • Gradle spawns a Daemon in the background that doesn't automatically pick up ENV changes. Are you running with `--no-daemon`, or making sure to kill the daemon after the environment changes? – Carl Mastrangelo Mar 01 '22 at 03:39

2 Answers2

0

I'd look closely at how your build process functions. Your question says you are issuing a 'gradlew' command, so first thing to check is "gradlew --version". If you get the expected version of both Gradle and Java from that, then all is well with your OS environment. Since your question also mentions "Make", my belief is that gradle is invoking Make. If that's the case, then see what environment is being provided (by Gradle) when Make is spun-up. Best guess is that the environment that 'Make' is using is somehow different than the one the OS has. e.g. it has a different (or non-existant) $PATH or $JAVA_HOME. Easy to check... in the 'Makefile', have it output things like 'env' or $PATH or $JAVA_HOME - verify they are what you expect.

Jeff Bennett
  • 996
  • 7
  • 18
-1

I Suggest using openJDK because the path can be configured automaticaly during instalation of openJDK. So you don't need to configure the path for jdk.

Here is the link: https://adoptopenjdk.net/

you can choose version 8, 11, and 16.

Hello world
  • 13
  • 1
  • 5
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 04 '22 at 07:49