# Java/jpl cmake test errors

**URL:** <https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177>\
**Category:** General\
**Created:** [April 16, 2020, 5:09am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177 "2020-04-16T05:09:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 16, 2020, 5:09am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/1 "2020-04-16T05:09:05Z")

</div>

I am getting the following errors when testing jpl:

```prolog
$ ctest -j 8 -V -R '.*java.*'
UpdateCTestConfiguration from :/home/u1/tmp/swipl-devel/build.release/DartConfiguration.tcl
UpdateCTestConfiguration from :/home/u1/tmp/swipl-devel/build.release/DartConfiguration.tcl
Test project /home/u1/tmp/swipl-devel/build.release
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 65
    Start 65: jpl:java_in_prolog

65: Test command: /home/u1/tmp/swipl-devel/build.release/src/swipl "-p" "foreign=:/home/u1/tmp/swipl-devel/build.release/packages/plunit" "-f" "none" "--no-packs" "-s" "/home/u1/tmp/swipl-devel/packages/jpl/test_jpl.pl" "-g" "test_jpl" "-t" "halt"
65: Test timeout computed to be: 10000000
test 64
    Start 64: jpl:prolog_in_java

64: Test command: /usr/sbin/env "SWI_HOME_DIR=../../home" "SWIPL_BOOT_FILE=../../home/boot.prc" "TEST_JPL=../../../packages/jpl/test_jpl.pl" "/usr/sbin/java" "-Djava.library.path=." "-classpath" "/usr/share/java/junit.jar:src/java/jpl.jar:src/java/jpltest.jar" "junit.textui.TestRunner" "org.jpl7.test.TestJUnit"
64: Test timeout computed to be: 10000000
64: Failed to invoke suite():org.jpl7.JPLException: unsupported blob type passed from Prolog
1/2 Test #64: jpl:prolog_in_java ...............***Failed 0.18 sec
65: % PL-Unit: jpl .
65: ERROR: /home/u1/tmp/swipl-devel/packages/jpl/test_jpl.pl:78:
65: test array_to_from_terms_1: received error: Java exception: org.jpl7.JPLException: unknown term type=10
65: ................................................[Thread 1 (main) at Thu Apr 16 01:01:40 2020] ../src/pl-wam.c:2299: discardChoicesAfter: Assertion failed: fr2->clause || true(fr2->predicate, P_FOREIGN)
65: C-stack trace labeled "assert_fail":
65: [0] save_backtrace() at /home/u1/tmp/swipl-devel/build.release/../src/os/pl-cstack.c:332 [0x7f44a97e2481]
65: [1] __assert_fail() at /home/u1/tmp/swipl-devel/build.release/../src/pl-assert.c:106 [0x7f44a97a0e76]
65: [2] discardChoicesAfter() at /home/u1/tmp/swipl-devel/build.release/../src/pl-wam.c:2299 (discriminator 2) [0x7f44a971797d]
65: [3] dbg_discardChoicesAfter() at /home/u1/tmp/swipl-devel/build.release/../src/pl-wam.c:2363 [0x7f44a9717c58]
65: [4] PL_next_solution() at /home/u1/tmp/swipl-devel/build.release/../src/pl-vmi.c:4598 [0x7f44a9710a67]
65: [5] query_loop() at /home/u1/tmp/swipl-devel/build.release/../src/pl-pro.c:144 [0x7f44a975562f]
65: [6] prologToplevel() at /home/u1/tmp/swipl-devel/build.release/../src/pl-pro.c:483 [0x7f44a9755e9b]
65: [7] PL_initialise() at /home/u1/tmp/swipl-devel/build.release/../src/pl-init.c:1091 [0x7f44a9798aec]
65: [8] /home/u1/tmp/swipl-devel/build.release/src/swipl(+0x1097) [0x55c0eb414097]
65: [9] __libc_start_main() at ??:? [0x7f44a9529023]
65: [10] /home/u1/tmp/swipl-devel/build.release/src/swipl(+0x10ee) [0x55c0eb4140ee]
2/2 Test #65: jpl:java_in_prolog ...............Child aborted***Exception: 17.24 sec

0% tests passed, 2 tests failed out of 2

Total Test time (real) = 17.24 sec

The following tests FAILED:
	64 - jpl:prolog_in_java (Failed)
	65 - jpl:java_in_prolog (Child aborted)
Errors while running CTest

```

with

```prolog
$ java -version
openjdk version "13.0.2" 2020-01-14
OpenJDK Runtime Environment (build 13.0.2+8)
OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode)

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 16, 2020, 6:47am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/2 "2020-04-16T06:47:08Z")

</div>

> [@swi](#):
>
> unsupported blob type passed from Prolog

> [@swi](#):
>
> unknown term type=10

Both suggest a mixup of versions, combining a wrong version of libswipl.so, jpl.so and/or jpl.jar. Maybe some environment variable leading to an old version, an old file copied to place where it is first found by the dynamic linker or Java, etc.

Of course it can be something else. So far these tests passed for the most recent build on all platforms.

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 16, 2020, 11:14am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/3 "2020-04-16T11:14:01Z")

</div>

Thanks, the jpl submodule had not updated properly. Now I am getting a new error:

```prolog
ctest -j 8 -V -R '.*java.*'  07:02:31  ✔ 0 
UpdateCTestConfiguration from :/home/u/tmp/swipl-devel/build.release/DartConfiguration.tcl
UpdateCTestConfiguration from :/home/u/tmp/swipl-devel/build.release/DartConfiguration.tcl
Test project /home/u/tmp/swipl-devel/build.release
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 64
    Start 64: jpl:prolog_in_java

64: Test command: /usr/sbin/env "SWI_HOME_DIR=../../home" "SWIPL_BOOT_FILE=../../home/boot.prc" "TEST_JPL=../../../packages/jpl/test_jpl.pl" "/usr/sbin/java" "-Djava.library.path=." "-classpath" "/usr/share/java/junit.jar:src/java/jpl.jar:src/java/jpltest.jar" "org.jpl7.test.TestJUnit4"
64: Test timeout computed to be: 10000000
test 65
    Start 65: jpl:java_in_prolog

65: Test command: /home/u/tmp/swipl-devel/build.release/src/swipl "-p" "foreign=:/home/u/tmp/swipl-devel/build.release/packages/plunit" "-f" "none" "--no-packs" "-s" "/home/u/tmp/swipl-devel/packages/jpl/test_jpl.pl" "-g" "test_jpl" "-t" "halt"
65: Test timeout computed to be: 10000000
64: JUnit version 4.12
64: Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
64: at java.base/java.lang.ClassLoader.defineClass1(Native Method)
64: at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
64: at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
64: at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
64: at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
64: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
64: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
64: at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
64: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
64: at org.junit.runner.Computer.getSuite(Computer.java:28)
64: at org.junit.runner.Request.classes(Request.java:75)
64: at org.junit.runner.JUnitCommandLineParseResult.createRequest(JUnitCommandLineParseResult.java:118)
64: at org.junit.runner.JUnitCore.runMain(JUnitCore.java:77)
64: at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
64: at org.jpl7.test.TestJUnit4.main(TestJUnit4.java:37)
64: Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
64: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
64: at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
64: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
64: ... 15 more
1/2 Test #64: jpl:prolog_in_java ...............***Failed 0.11 sec
65: % PL-Unit: jpl .......................................................................................... done
65: % 3 tests are blocked:
65: % /home/u/tmp/swipl-devel/packages/jpl/test_jpl.pl:610:
65: test method_static_echo_float_4: we do not yet widen unbounded integers to floats or doubles
65: % /home/u/tmp/swipl-devel/packages/jpl/test_jpl.pl:914:
65: test set_field_static_shadow_1: we do not yet resolve same-named shadowed fields
65: % /home/u/tmp/swipl-devel/packages/jpl/test_jpl.pl:1193:
65: test throw_java_exception_1: part of the error term is nondeterministic: we need to match with _
65: % 90 tests passed
2/2 Test #65: jpl:java_in_prolog ............... Passed 0.55 sec

The following tests passed:
	jpl:java_in_prolog

50% tests passed, 1 tests failed out of 2

Total Test time (real) = 0.56 sec

The following tests FAILED:
	64 - jpl:prolog_in_java (Failed)
Errors while running CTest

```

It happens because `JUnit 4.11` and above require `hamcrest-core.jar` in the class path, as shown in this [stackoverflow](https://stackoverflow.com/questions/14539072/java-lang-noclassdeffounderror-org-hamcrest-selfdescribing) question. I do have it:

```prolog
$ ls -al /usr/share/java/hamcrest-core.jar
lrwxrwxrwx 21 root 5 Jun 2018 /usr/share/java/hamcrest-core.jar -> hamcrest/core-1.3.jar

```

but it is not included in the classpath (from the error above):

```prolog
64: Test command: /usr/sbin/env "SWI_HOME_DIR=../../home" "SWIPL_BOOT_FILE=../../home/boot.prc" "TEST_JPL=../../../packages/jpl/test_jpl.pl" "/usr/sbin/java" "-Djava.library.path=." "-classpath" "/usr/share/java/junit.jar:src/java/jpl.jar:src/java/jpltest.jar" "org.jpl7.test.TestJUnit4"

```

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 17, 2020, 11:02am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/4 "2020-04-17T11:02:11Z")

</div>

Thanks for pointing this out; I recently updated JPL and migrated JUnit from v3 to v4, and also clean that up a lot (still a much bigger clean-up and restructuring is in a branch)

You are right that `JUnit4` seems to require `hamcrest-core.jar`, and I do have it in my system as you but the test passes well (or any individual call via Java) without that being in the classpath…

Need to investigate, I have re-opened [issue #40](https://github.com/SWI-Prolog/packages-jpl/issues/40) related to this transition:

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 17, 2020, 12:22pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/5 "2020-04-17T12:22:01Z")

</div>

Hi @swi,

JUnit4 needs `hamcrest-core.jar` and I have them both in `/usr/share/java`.

What I find strange in your trace is that it is looking for `/usr/share/java/junit.jar` which is not correct as that is v3. It should look for `/usr/share/java/junit4.jar` and then it will pick up the dependency automatically.

See the command that cmake runs:

`62: Test command: /usr/bin/env "SWI_HOME_DIR=../../home" "SWIPL_BOOT_FILE=../../home/boot.prc" "TEST_JPL=../../../packages/jpl/test_jpl.pl" "/usr/lib/jvm/java-8-oracle/bin/java" "-Djava.library.path=." "-classpath" "/usr/share/java/junit4.jar:src/java/jpl.jar:src/java/jpltest.jar" "org.jpl7.test.junit.Tests"`

I did modify the framework to look for `junit4.jar` and not `junit.jar`, not sure why your system is picking that one up instead:

> <https://github.com/SWI-Prolog/packages-jpl/blob/0480d18be7bff207a8306f8c8157feacfe6baa8a/cmake/JUnit.cmake>

Since you seem to have a development version of SWI-JPL, maybe you want to try the latest junit4 branch which has the tests in better shape? I am curious if it also picks up `junit.jar`

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 17, 2020, 4:43pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/6 "2020-04-17T16:43:19Z")

</div>

Hi @ssardina,

Thank you for your reply, I am using `archlinux` and the `junit` package comes with these files:

```prolog
/usr/share/java/junit-4.12.jar
/usr/share/java/junit.jar

```

and

```prolog
$ ls -al /usr/share/java/junit.jar
lrwxrwxrwx 14 root 4 Jun 2018 /usr/share/java/junit.jar -> junit-4.12.jar

```

As you can see `junit.jar` is a symlink to `junit-4.12.jar`. This is done automatically by the archlinux package management system.

Perhaps you could modify the cmake script to find any file with the regex patern `junit.?4.*\.jar`  
This would match both `junit4.jar` and `junit-4.12.jar`, I’ll be happy to test that.

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 19, 2020, 12:05pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/7 "2020-04-19T12:05:35Z")

</div>

Hi @swi

ahh I see, great stuff you gave me. OK I have followed your advice and now search for those patters for `junit`. Unfortunately GLOB for CMAKE does not find files by regexp so it was a bit more explicit but should work.

Would you be able to test branch `enhacement/junit4` to see if it works? It also contains all the tests much better organized in test suites (and additional tests that were standalone tests), so don’t be alarmed if you see a much verbose output when you run the test!

Let me know how it goes. And if it works I will make a PR to go into master.

Thanks!

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 19, 2020, 1:30pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/8 "2020-04-19T13:30:02Z")

</div>

> [@ssardina](#):
>
> Would you be able to test branch `enhacement/junit4` to see if it works?

With that branch, jpl does not build, I am getting this error:

```BASH
$ ninja
[882/2399] Building Java objects for jpl_jar.jar
Note: org/jpl7/fli/atom_t.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[889/2399] Building Java objects for jpltest.jar
FAILED: packages/jpl/src/java/CMakeFiles/jpltest.dir/java_compiled_jpltest 
cd /home/u1/tmp/swipl-devel/packages/jpl/src/java && /usr/sbin/javac -classpath :/home/u1/tmp/swipl-devel/packages/jpl/src/java:/home/u1/tmp/swipl-devel/build.release/packages/jpl/src/java:/usr/share/java/junit-4.12.jar -d /home/u1/tmp/swipl-devel/build.release/packages/jpl/src/java/CMakeFiles/jpltest.dir @/home/u1/tmp/swipl-devel/build.release/packages/jpl/src/java/CMakeFiles/jpltest.dir/java_sources && /usr/bin/cmake -E touch /home/u1/tmp/swipl-devel/build.release/packages/jpl/src/java/CMakeFiles/jpltest.dir/java_compiled_jpltest
org/jpl7/test/JPLTestSuite.java:21: error: cannot find symbol
        org.jpl7.test.junit.RationalTest.class,
                           ^
  symbol: class RationalTest
  location: package org.jpl7.test.junit
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
[898/2399] Building CXX object packages/swipl-win/CMakeFiles/swipl-win.dir/pqConsole.cpp.o
ninja: build stopped: subcommand failed.

```

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 20, 2020, 3:09am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/9 "2020-04-20T03:09:57Z")

</div>

Thanks @swi for trying quick, that helps a lot!

Sorry, somehow a [wrong text](https://github.com/SWI-Prolog/packages-jpl/commit/03fff6f2d116422a58b0c15bac5adf70b43c8496#diff-381d6258c9f53c6ac14031ced77938c0) (`RationalTest.class`) from another branch got into the last commit wrongly!

I have fixed that, can you pull again and re-try. Thanks!

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 20, 2020, 3:50am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/10 "2020-04-20T03:50:24Z")

</div>

Thanks, it builds fine now, but it still fails:

```prolog
ctest -j 8 -V -R '.*java.*'
UpdateCTestConfiguration from :/home/u1/tmp/swipl-devel/build.release/DartConfiguration.tcl
UpdateCTestConfiguration from :/home/u1/tmp/swipl-devel/build.release/DartConfiguration.tcl
Test project /home/u1/tmp/swipl-devel/build.release
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 64
    Start 64: jpl:prolog_in_java

64: Test command: /usr/sbin/env "CLASSPATH=src/java/jpl.jar" "SWI_HOME_DIR=../../home" "SWIPL_BOOT_FILE=../../home/boot.prc" "TEST_FILE=/home/u1/tmp/swipl-devel/packages/jpl/../../packages/jpl/src/java/org/jpl7/test/test_jpl.pl" "TEST_DIR=/home/u1/tmp/swipl-devel/packages/jpl/../../packages/jpl/src/java/org/jpl7/test" "/usr/sbin/java" "-Djava.library.path=." "-classpath" "/usr/share/java/junit-4.12.jar:src/java/jpl.jar:src/java/jpltest.jar" "org.jpl7.test.JPLTestSuiteRunner"
64: Test timeout computed to be: 10000000
test 65
    Start 65: jpl:java_in_prolog

65: Test command: /home/u1/tmp/swipl-devel/build.release/src/swipl "-p" "foreign=:/home/u1/tmp/swipl-devel/build.release/packages/plunit" "-f" "none" "--no-packs" "-s" "/home/u1/tmp/swipl-devel/packages/jpl/test_jpl.pl" "-g" "test_jpl" "-t" "halt"
65: Test timeout computed to be: 10000000
65: ERROR: Prolog initialisation failed:
65: ERROR: script_file `'/home/u1/tmp/swipl-devel/packages/jpl/test_jpl.pl'' does not exist
1/2 Test #65: jpl:java_in_prolog ...............***Failed 0.02 sec
64: Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
64: at java.base/java.lang.ClassLoader.defineClass1(Native Method)
64: at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
64: at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
64: at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
64: at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
64: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
64: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
64: at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
64: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
64: at org.junit.runner.Computer.getSuite(Computer.java:28)
64: at org.junit.runner.Request.classes(Request.java:75)
64: at org.junit.runner.JUnitCore.run(JUnitCore.java:105)
64: at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:62)
64: at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:49)
64: at org.jpl7.test.JPLTestSuiteRunner.main(JPLTestSuiteRunner.java:10)
64: Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
64: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
64: at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
64: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
64: ... 15 more
2/2 Test #64: jpl:prolog_in_java ...............***Failed 0.10 sec

0% tests passed, 2 tests failed out of 2

Total Test time (real) = 0.10 sec

The following tests FAILED:
	64 - jpl:prolog_in_java (Failed)
	65 - jpl:java_in_prolog (Failed)
Errors while running CTest

```

As you can see it does recognize the `junit-4.12.jar` - so your fix for that is working; but it does not add the `hamcrest-core.jar` file to the class path.

My `hamcrest-core.jar` is in `/usr/share/java` (it is a symlink):

```prolog
$ ls /usr/share/java/hamcrest-core.jar
/usr/share/java/hamcrest-core.jar

```

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 20, 2020, 7:25am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/11 "2020-04-20T07:25:55Z")

</div>

OK we are getting there. Your JAR was found. Thanks for testing it, very helpful as I can only test in my configuration!

I thought the dependency would be found automatically because JUNIT jar includes it in its `MANIFEST.MF`

```prolog
Implementation-Title: JUnit
Implementation-URL: http://junit.org
Implementation-Vendor: JUnit
Implementation-Vendor-Id: junit
Implementation-Version: 4.12
Import-Package: org.hamcrest;version="1.3",org.hamcrest.core;version="1.
  3"

```

Wonder if your JUNIT JAR has that part.

In any case, I have changed the script to explicitly add it to the CLASSPATH. Can you pull and check?

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 20, 2020, 8:30am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/12 "2020-04-20T08:30:51Z")

</div>

Thanks! It found the `hamcrest` jar now. Now I get this error:

```prolog
[...]
test 64
    Start 64: jpl:prolog_in_java

64: Test command: /usr/sbin/env "CLASSPATH=src/java/jpl.jar" "SWI_HOME_DIR=../../home" "SWIPL_BOOT_FILE=../../home/boot.prc" "TEST_FILE=/home/u1/tmp/swipl-devel/packages/jpl/../../packages/jpl/src/java/org/jpl7/test/test_jpl.pl" "TEST_DIR=/home/u1/tmp/swipl-devel/packages/jpl/../../packages/jpl/src/java/org/jpl7/test" "/usr/sbin/java" "-Djava.library.path=." "-classpath" "/usr/share/java/junit-4.12.jar:/usr/share/java/hamcrest-core.jar:src/java/jpl.jar:src/java/jpltest.jar" "org.jpl7.test.JPLTestSuiteRunner"
64: Test timeout computed to be: 10000000
65: ERROR: Prolog initialisation failed:
65: ERROR: script_file '/home/u1/tmp/swipl-devel/packages/jpl/test_jpl.pl' does not exist
1/2 Test #65: jpl:java_in_prolog ...............***Failed 0.02 sec
[...]
2/2 Test #64: jpl:prolog_in_java ............... Passed 0.58 sec

The following tests passed:
	jpl:prolog_in_java

50% tests passed, 1 tests failed out of 2

Total Test time (real) = 0.59 sec

The following tests FAILED:
	65 - jpl:java_in_prolog (Failed)
Errors while running CTest

```

It seems it can’t find `test_jpl.pl`. The file does not exist in the cmake build directory, but it is found in the original src directory:

```prolog
$ cd build.release
$ find packages/jpl -iname 'test_jpl.pl'
$ find ../packages/jpl -iname 'test_jpl.pl'
../packages/jpl/src/java/org/jpl7/test/test_jpl.pl

```

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 20, 2020, 8:55am UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/13 "2020-04-20T08:55:53Z")

</div>

Hi. Thanks for running it quickly, it helps me a lot.

Yes `test_jpl.pl` is in the original source dir. I have fixed and simplified the dir and TEST\_FILE was not needed. Strange why it didn’t give me error here, but the path is anyways way too complicated as it is.

can you pull and try? Seems we are making together prioress step-by-step! **THANKS!**

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 20, 2020, 4:31pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/14 "2020-04-20T16:31:29Z")

</div>

Still doesn’t find test\_jpl.pl:

```prolog
65: Test command: /home/u1/tmp/swipl-devel/build.release/src/swipl "-p" "foreign=:/home/u1/tmp/swipl-devel/build.release/packages/plunit" "-f" "none" "--no-packs" "-s" "/home/u1/tmp/swipl-devel/packages/jpl/test_jpl.pl" "-g" "test_jpl" "-t" "halt"
65: Test timeout computed to be: 10000000
65: ERROR: Prolog initialisation failed:
65: ERROR: script_file `'/home/u1/tmp/swipl-devel/packages/jpl/test_jpl.pl'' does not exist
1/2 Test #65: jpl:java_in_prolog ...............***Failed 0.03 sec

```

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 20, 2020, 4:55pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/15 "2020-04-20T16:55:08Z")

</div>

Note that the [`test_lib` CMake function from SWI-Prolog](https://github.com/SWI-Prolog/swipl-devel/blob/aa676aceb883c8df65233aa0d8c39d96fbbcf8bb/packages/cmake/PrologPackage.cmake#L300) does not use the `TEST_DIR` parameter, it uses the following to figure out the prolog source file for testing:

```prolog
set(test_source "${CMAKE_CURRENT_SOURCE_DIR}/${test_source_basename}")

```

So it expects the `test_jpl.pl` file as `packages/jpl/test_jpl.pl`

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 20, 2020, 8:53pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/16 "2020-04-20T20:53:56Z")

</div>

mmmm thanks for staying with me.

So, seems the `prolog_in_java` test now works on your side then?

But now I see the problem now is `java_in_prolog`, yes good pointer let me check and fix that as well.

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 20, 2020, 9:39pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/17 "2020-04-20T21:39:53Z")

</div>

So it was not a good idea to move `test_jpl.pl` inside the source tree, as it does not follow the “standard” for `test_xxx.pl` on all the other packages.

I reverted that back and adapted all tests. Hopefully this will work on both tests for you, let me know! Thanks!

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 20, 2020, 10:16pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/18 "2020-04-20T22:16:06Z")

</div>

Success! All tests pass now:

```prolog

The following tests passed:
	jpl:prolog_in_java
	jpl:java_in_prolog

100% tests passed, 0 tests failed out of 2

```

Although some exceptions are thrown:

```prolog
[...]
64: Starting test: testOpenGetClose1 (Tests)
64: Starting test: testOpenGetClose2 (Tests)
64: org.jpl7.test.junit.JRef: PrologException: error(existence_error(source_sink, 'test_jpl.pl'), _83)
64: org.jpl7.PrologException: PrologException: error(existence_error(source_sink, 'test_jpl.pl'), _83)
64: at org.jpl7.Query.fetchNextSolution(Query.java:437)
64: at org.jpl7.Query.hasMoreSolutions(Query.java:341)
64: at org.jpl7.Query.oneSolution(Query.java:815)
64: at org.jpl7.Query.hasSolution(Query.java:893)
64: at org.jpl7.test.junit.JPLTest.consultTestFile(JPLTest.java:77)
64: at org.jpl7.test.junit.JRef.setUp(JRef.java:36)
64: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
64: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
64: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
64: at java.base/java.lang.reflect.Method.invoke(Method.java:567)
64: at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
64: at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
64: at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
64: at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
64: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
64: at org.junit.runners.Suite.runChild(Suite.java:128)
64: at org.junit.runners.Suite.runChild(Suite.java:27)
64: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
64: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
64: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
64: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
64: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
64: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
64: at org.junit.runners.Suite.runChild(Suite.java:128)
64: at org.junit.runners.Suite.runChild(Suite.java:27)
64: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
64: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
64: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
64: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
64: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
64: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
64: at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
64: at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
64: at org.junit.runner.JUnitCore.run(JUnitCore.java:105)
64: at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:62)
64: at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:49)
64: at org.jpl7.test.JPLTestSuiteRunner.main(JPLTestSuiteRunner.java:10)
64: org.jpl7.test.junit.MutualRecursion: PrologException: error(existence_error(source_sink, 'test_jpl.pl'), _87)
64: org.jpl7.PrologException: PrologException: error(existence_error(source_sink, 'test_jpl.pl'), _87)
64: at org.jpl7.Query.fetchNextSolution(Query.java:437)
64: at org.jpl7.Query.hasMoreSolutions(Query.java:341)
64: at org.jpl7.Query.oneSolution(Query.java:815)
64: at org.jpl7.Query.hasSolution(Query.java:893)
64: at org.jpl7.test.junit.JPLTest.consultTestFile(JPLTest.java:77)
64: at org.jpl7.test.junit.MutualRecursion.setUp(MutualRecursion.java:35)
64: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
64: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
64: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
64: at java.base/java.lang.reflect.Method.invoke(Method.java:567)
64: at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
64: at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
64: at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
64: at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
64: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
64: at org.junit.runners.Suite.runChild(Suite.java:128)
64: at org.junit.runners.Suite.runChild(Suite.java:27)
64: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
64: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
64: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
64: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
64: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
64: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
64: at org.junit.runners.Suite.runChild(Suite.java:128)
64: at org.junit.runners.Suite.runChild(Suite.java:27)
64: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
64: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
64: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
64: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
64: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
64: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
64: at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
64: at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
64: at org.junit.runner.JUnitCore.run(JUnitCore.java:105)
64: at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:62)
64: at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:49)
64: at org.jpl7.test.JPLTestSuiteRunner.main(JPLTestSuiteRunner.java:10)
64: ********* Test successful? false

```

---

<div class="post-metadata">

**Author:** ![ssardina](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ssardina/32/189_2.png) [@ssardina](https://swi-prolog.discourse.group/u/ssardina)\
**Post date:** [April 20, 2020, 10:52pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/19 "2020-04-20T22:52:59Z")

</div>

OK I know that! Yes this is because I am developing both on CMAKE and IntelliJ, a bit of a mix.

Now I have sorted all out I think and do not use TEST\_DIR anymore.

Can you check one more? Sorry! I bet this is the last one! 😉

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [April 20, 2020, 10:57pm UTC](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177/20 "2020-04-20T22:57:09Z")

</div>

Happy to help! Working great now, with no exceptions!

```prolog
[...]
64: Starting test: testOpenGetClose1 (Tests)
64: Starting test: testOpenGetClose2 (Tests)
64: ********* Test successful? true
2/2 Test #64: jpl:prolog_in_java ............... Passed 0.73 sec

The following tests passed:
	jpl:java_in_prolog
	jpl:prolog_in_java

100% tests passed, 0 tests failed out of 2

Total Test time (real) = 0.74 sec

```

[Next page](https://swi-prolog.discourse.group/t/java-jpl-cmake-test-errors/2177.md?page=2)
