# Embedding Julia in Java example, "Unreachable reached"

**URL:** <https://discourse.julialang.org/t/embedding-julia-in-java-example-unreachable-reached/16126>\
**Category:** General Usage\
**Created:** [October 10, 2018, 6:00pm UTC](https://discourse.julialang.org/t/embedding-julia-in-java-example-unreachable-reached/16126 "2018-10-10T18:00:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![samtkaplan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samtkaplan/32/2000_2.png) [@samtkaplan](https://discourse.julialang.org/u/samtkaplan)\
**Post date:** [October 10, 2018, 6:00pm UTC](https://discourse.julialang.org/t/embedding-julia-in-java-example-unreachable-reached/16126/1 "2018-10-10T18:00:49Z")

</div>

Hello,

I am trying to embed julia into a Java library. However, the java code ends up crashing with the following error “Unreachable reached at ”.

I managed to put together a minimal example which I posted in a GItHub Gist:

[https://gist.github.com/samtkaplan/35a1ce57145143b6e34f77ced8096611](https://gist.github.com/samtkaplan/35a1ce57145143b6e34f77ced8096611)

The files in the Gist should be placed in the following directory structure:

```julia
src/makefile
src/org_foo_bug_jni_Bug.c
src/org_foo_bug_jni_Bug.h
src/org/foo/bug/jni/Bug.java
demo/org/foo/bug/jni/Demo.java

```

Then, you can compile the code with,

```julia
cd src
make
make install
cd ..

```

Then, you can run the demo that produces the crash with,

```julia
cd demo
javac -cp ../deps/usr/share/java/bug.jar org/foo/bug/jni/Demo.java
env LD_PRELOAD="libjulia.so" java -cp .:../deps/usr/share/java/bug.jar -Djava.library.path=../deps/usr/lib org.foo.bug.jni.Demo

```

Note that if you remove the `jl_eval_string("using Pkg")` line in `org_foo_bug_jni_Bug.c` or replace it with something like `jl_eval_string("println(\"Hello\")")`, then the program runs without crashing.

As a secondary question, I’m not sure why the “LD\_PRELOAD” is required. I got that tip from another Discorse topic thread which I’m having troubles finding at the moment.

Thanks for your time. I’m using julia 1.0.1 and java 1.6

Sam
