# loading vtk in java fails

**URL:** https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467
**Category:** Support
**Created:** [April 2, 2025, 9:20am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467 "2025-04-02T09:20:14Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 2, 2025, 9:20am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/1 "2025-04-02T09:20:15Z")

</div>

Hello together,

I try to load vtk 9.4.1 into java. I have build with wrappings, vtk jar and wrappings dll are build.  
I copied it al together and try to to call vtkNativeLibrary.LoadAllNativeLibraries();.

It fails. Several dlls cannot be loaded, e.g. vtkTestingRendering. DependencyWalker is green. I traced it down to vtkFiltersCellGrid. It cannot be loaded into java. What is going on here? Is this broken?

---

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 3, 2025, 9:37am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/2 "2025-04-03T09:37:38Z")

</div>

I now tested the standard example on several machines. The error is reproducable in both debug and release dlls. I don’t use jogl. I looks like the java wrapping is fundamental broken.

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [April 4, 2025, 6:51pm UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/3 "2025-04-04T18:51:56Z")

</div>

Are you using our maven published package? @vbolea

---

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 6, 2025, 1:34pm UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/4 "2025-04-06T13:34:49Z")

</div>

No, I need to build VTK manually with Java wrappings because my build process produces custom code in additional DLLs and includes patches to several VTK classes.

My current workflow is straightforward: I configure the build environment using CMake and Ninja, then execute the build. Although the build completes without errors, running the example results in crashes when loading multiple DLLs. I tried to disable some modules, but it seems that fundamental dlls cannot be loaded.

I tested that on several machines, always the same.

---

<div class="post-metadata">

### Author: ![vbolea](https://discourse.vtk.org/user_avatar/discourse.vtk.org/vbolea/32/4060_2.png) [@vbolea](https://discourse.vtk.org/u/vbolea)
#### Post date: [April 8, 2025, 5:08pm UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/5 "2025-04-08T17:08:50Z")

</div>

Hi @metamurk, I have been maintaining Java (Maven) builds in the release branch of VTK. You could try our latest release (9.4.2), in that release we include a few changes in the way that we build/run-time link VTK JAVA (Maven). Note all of this is WIP at the moment and we are currently only targeting MAVEN as the way for users to install VTK JAVA.

In addition to that, here are the flags that we use to build our MAVEN artifacts in our CI, you might not need all of this vars (since you are not using maven), but you definitely have to disable the modules below.

```auto
  set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
  set(JOGL_VERSION "2.3.2" CACHE STRING "")

  # Naming is <arch-platform-build_type> we avoid adding numbers in the arch
  # such as 64/86 since some maven versions fail to properly parse it.
  string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
  set(native_artifacts
    darwin-amd-${build_type}
    darwin-arm-${build_type}
    linux-amd-${build_type}
    windows-amd-${build_type}
  )
  set(MAVEN_NATIVE_ARTIFACTS "${native_artifacts}" CACHE STRING "" FORCE)
  unset(build_type)
  unset(native_artifacts)

  set(MAVEN_VTK_ARTIFACT_SUFFIX "-java${VTK_JAVA_TARGET_VERSION}" CACHE STRING "")
  # Disable snapshots for tag releases and also when the env variable
  # VTK_JAVA_FORCE_RELEASE is defined through the Gitlab schedule pipeline UI.
  # Note that VTK_JAVA_FORCE_RELEASE is used to create/override VTK java
  # releases.
  if (NOT DEFINED ENV{CI_COMMIT_TAG} AND NOT DEFINED ENV{VTK_JAVA_FORCE_RELEASE})
    set(MAVEN_VTK_SNAPSHOT "-SNAPSHOT" CACHE STRING "")
  endif()
  set(VTK_BUILD_TESTING OFF CACHE BOOL "" FORCE)
  set(VTK_CUSTOM_LIBRARY_SOVERSION "" CACHE STRING "")
  set(VTK_CUSTOM_LIBRARY_VERSION "" CACHE STRING "")
  set(VTK_DEBUG_LEAKS OFF CACHE BOOL "" FORCE)
  set(VTK_GROUP_ENABLE_Rendering "YES" CACHE STRING "")
  set(VTK_JAVA_JOGL_COMPONENT "YES" CACHE STRING "")
  set(VTK_MODULE_ENABLE_VTK_RenderingOpenXR NO CACHE STRING "" FORCE)
  set(VTK_MODULE_ENABLE_VTK_TestingCore NO CACHE STRING "")
  set(VTK_MODULE_ENABLE_VTK_TestingDataModel NO CACHE STRING "")
  set(VTK_MODULE_ENABLE_VTK_TestingGenericBridge NO STRING STRING "")
  set(VTK_MODULE_ENABLE_VTK_TestingIOSQL NO CACHE STRING "")
  set(VTK_MODULE_ENABLE_VTK_TestingRendering NO CACHE STRING "")
  set(VTK_VERSIONED_INSTALL "OFF" CACHE BOOL "" FORCE)
set(VTK_MODULE_ENABLE_VTK_vtkvtkm NO CACHE STRING "") # Java Wrap errors in windows  

```

---

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 10, 2025, 1:57pm UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/7 "2025-04-10T13:57:20Z")

</div>

Ok, thanks. I’ll tried that out and it does not work.

A documentation would help. The behavior is cryptic; you seem to run from one problem to the next and all you can do is try and error.

Just unpack it. Running the usual CMake setup and run ninja build results in linker crashes such as:

```auto
java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: C:\HEAD\env\app\lib\vtkFiltersCellGridJava.dll: Eine DLL-Initialisierungsroutine ist fehlgeschlagen

```

Redist is installed, every depended DLL is available. Something in the dll seems to be disliked by the java vm when it is build in a certain way. I had a configuration which was loadable, but after a windows update it fails again with the same errors. The thing was that in every case it worked, the jaring failed and I had to jar it by hand.

It would be awesome if anybody had an idea what could cause the builded dll to be rejected by the jvm and which cmake flag is producing that.

The unloadable dlls are all java wrapping dlls:  
vtkFiltersCellGridJava  
vtkIOLegacyJava  
vtkParallelCoreJava …

---

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 14, 2025, 4:53pm UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/9 "2025-04-14T16:53:57Z")

</div>

@vbolea @Sebastien_Jourdain

Ok, after many tries I figured out something:

- The vtk java build fails runs if you use a modern JVM (21) The dependencies are broken and wont load.
- If you use an old Java for the build (e.g. 9) the build fails at jar-creation when you build debug Dlls. These Dlls are loadable.
- If you build release with old java, the dlls fails again to be loaded into a modern JVM.

So there is no way at the moment to build a vtk 9.4.2. release and load it into an actual JVM.  
So there is no migration path for java products based on vtk at the moment.

Is there a ticket for this or anymore knowledge? Could we support somehow? For us this is a real major issue, cause we have several commerical products depending on these wrappings massivly . Migration is necessary, major feature are blocked…

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [April 17, 2025, 5:13am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/10 "2025-04-17T05:13:21Z")

</div>

Is this relevant?

> [@Building vtk 9.4.0 on windows Java](https://discourse.vtk.org/t/building-vtk-9-4-0-on-windows-java/14936/80):
>
> Good morning David. Ever since vtk\_9.4.1 was released, I have been building the RELEASE version with vs 2022. The build was clean but java would not load, never mind run. The loading error suggested missing DLL’s of which I downloaded many in trial and error. Nothing worked and I almost gave up. I have just built the DEBUG version of it and it LOADS & RUNS! There is obviously something in DEBUG that is missing from RELEASE. No idea what it is but I shall look for it while happily running my new…

---

<div class="post-metadata">

### Author: ![Ngwarai](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/9f8e36/32.png) [@Ngwarai](https://discourse.vtk.org/u/Ngwarai)
#### Post date: [April 17, 2025, 6:46am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/11 "2025-04-17T06:46:23Z")

</div>

Good morning Todd and thanks for getting in touch. Yes, this was the problem with java 9.4.0. The problem was ‘kind of solved’ in 9.4.1 in that the Debug was fine while the Release would not run after a clean build.

We seem to have the same problems with 9.4.2. The build is clean but neither the Debug nor the Release will run. David identified something which was put into 9.4.1 but may have been dropped again.

I have attached the run error log I am getting. My build system is CMake 4.0.0 and VS 2022- latest update. I have also attached, for confirmation, the directory listing showing the file the system can’t load as missing.

I shall be most grateful if you have any insight into this or tricks I can try to identify the solution. Thanks again and good luck.

ngwarai

> **(attachments)**
>
> [runErrorLog.txt](https://discourse.vtk.org/uploads/short-url/xh35h1mO2cqpzsyYFnIK1IGTeml.txt) (9.51 KB)  
> [dir.txt](https://discourse.vtk.org/uploads/short-url/snVFnyuJeRMvCTtRK2JHpcswLW2.txt) (15.2 KB)

---

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 17, 2025, 7:48am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/12 "2025-04-17T07:48:15Z")

</div>

Hi Todd, thank you.

I think the behavior is the same as in 9 4.1 . Debug runs but Release not. Without Release DLLs in Java, we cannot migrate anymore to higher vtk versions. Debug Dlls are significantly slower.

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [April 18, 2025, 1:03am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/13 "2025-04-18T01:03:55Z")

</div>

Did you try setting `VTK_JAVA_RELEASE_VERSION` in CMake? Otherwise it defaults to version 8

The only other thing I can suggest is to try `VTK_BUILD_MAVEN_PKG=OFF` and do a manual build of the JARs.

---

<div class="post-metadata">

### Author: ![Ngwarai](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/9f8e36/32.png) [@Ngwarai](https://discourse.vtk.org/u/Ngwarai)
#### Post date: [April 18, 2025, 5:43am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/14 "2025-04-18T05:43:15Z")

</div>

Good morning. No, I have not tried that one. I will give it a bash and report back. Thanks and happy Easter

---

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 22, 2025, 8:06am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/15 "2025-04-22T08:06:28Z")

</div>

I don’t think that Javaside flags like Release Version could have any influance on it.  
JVM really rejects loading vtk Release DLLs in every newer version (so java Wrapping practically doesn’t work at all for newer vtk versions). This must have something to do with the dependcy hierachies of VTK and the JVM …

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [April 22, 2025, 8:11am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/16 "2025-04-22T08:11:34Z")

</div>

and you think the dependency changes between _ **debug** _ and _ **release** _ builds?

---

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 22, 2025, 8:22am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/17 "2025-04-22T08:22:31Z")

</div>

Yes. With the same Cmake config debug build can be loaded, while release builds are failing.

It’s not really the static depedency, they are all good. Also there is no dynamic loading. Something else must prevent the JVM from loading them. And it’s not all Dlls, but a subset which cannot be loaded.

---

<div class="post-metadata">

### Author: ![Ngwarai](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/9f8e36/32.png) [@Ngwarai](https://discourse.vtk.org/u/Ngwarai)
#### Post date: [April 22, 2025, 10:39am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/18 "2025-04-22T10:39:29Z")

</div>

Following this very keenly. I hope a solution can be found before 9.5.0 is out, else the problem will manifest itself again in the new release. Thanks very much and good luck.

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [April 22, 2025, 10:41am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/19 "2025-04-22T10:41:03Z")

</div>

Have you tried what I suggested?

---

<div class="post-metadata">

### Author: ![Ngwarai](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/9f8e36/32.png) [@Ngwarai](https://discourse.vtk.org/u/Ngwarai)
#### Post date: [April 22, 2025, 10:52am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/20 "2025-04-22T10:52:36Z")

</div>

Did you try setting `VTK_JAVA_RELEASE_VERSION` in CMake? Otherwise it defaults to version 1.8

Thanks Todd. No I haven’t yet. I was confused somewhat, because I have no alternative java version on my build machine, only the 1.8. I will have another go at it and report back. Thanks

ngwarai

---

<div class="post-metadata">

### Author: ![metamurk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/metamurk/32/9665_2.png) [@metamurk](https://discourse.vtk.org/u/metamurk)
#### Post date: [April 22, 2025, 11:06am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/21 "2025-04-22T11:06:02Z")

</div>

I just tried it. Makes no difference…

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [April 22, 2025, 11:07am UTC](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467/22 "2025-04-22T11:07:30Z")

</div>

Tried what? Setting `VTK_JAVA_RELEASE_VERSION` = x?

What about manually building the JARs?

[Next page](https://discourse.vtk.org/t/loading-vtk-in-java-fails/15467.md?page=2)
