SpencerPark / IJava

A Jupyter kernel for executing Java code.
MIT License
1.1k stars 217 forks source link

Why can't find the class? "kernel = new JavaKernel();" #34

Open WeichengDDD opened 6 years ago

WeichengDDD commented 6 years ago

Exception in thread "main" java.lang.NoClassDefFoundError: jdk/jshell/EvalException at io.github.spencerpark.ijava.IJava.main(IJava.java:104) Caused by: java.lang.ClassNotFoundException: jdk.jshell.EvalException at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source) at java.base/java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more

SpencerPark commented 6 years ago

This is very strange. Is this error preventing you from starting the kernel or does it appear when you are running some code in the kernel that is trying to start up a new kernel. I am not sure why you are getting an EvalException if the situation is the former.

If this is indeed code in a notebook or similar, could you include the code here along with the version of the kernel that is causing the exception? Thanks!

buhanec commented 6 years ago

Seeing the same error after installing from source, jupyter hangs indefinitely:

alenb@ALEN-BOOK ~
03:46:34 7> java -version
java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
alenb@ALEN-BOOK ~
03:46:38 8> python --version
Python 3.6.5 :: Anaconda, Inc.
alenb@ALEN-BOOK ~
03:46:44 9> jupyter --version
4.4.0
alenb@ALEN-BOOK ~
03:46:53 10> jupyter kernelspec list
Available kernels:
  java       C:\Users\alenb\AppData\Roaming\jupyter\kernels\java
  python3    C:\Users\alenb\Anaconda3\share\jupyter\kernels\python3
alenb@ALEN-BOOK ~
03:47:06 11> jupyter console --kernel=java
Exception in thread "main" java.lang.NoClassDefFoundError: jdk/jshell/EvalException
        at io.github.spencerpark.ijava.IJava.main(IJava.java:104)
Caused by: java.lang.ClassNotFoundException: jdk.jshell.EvalException
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 1 more

For whatever reason moving to JDK 11 solved the issue. Might have been some env weirdness with JDK 10?

SpencerPark commented 6 years ago

Ah my apologies, I read the original stacktrace wrong. The exception was a NoClassDefFoundError not an EvalException. This is the case when using the jre and not the jdk as jshell is in the jdk.jshell module.

On your original (broken) setup, if you still have everything ready to go, would you mind running java --list-modules | findstr "jdk.jshell" and assert that it indeed outputs jdk.jshel@... If not that would imply that you have the jre 10 in your path and not jdk.

cyrillemidingoyi commented 6 years ago

Please, How to use the jdk as jshell instead of jre

SpencerPark commented 6 years ago

@cyrillemidingoyi The you can get a jdk build from https://jdk.java.net/ (which looks like jdk 11 is the general release at the time of writing this). Then find where it is installed and make sure to add the bin folder in the installation to the front of your PATH.

For example on windows I have jdk 10 installed in C:\Program Files\Java\jdk-10.0.1 so to make sure I am using that one I can permanently set the PATH via editing the system environment variables (Google this part if you aren't sure) or in cmd before running jupyter notebook, set the path with set PATH="C:\Program Files\Java\jdk-10.0.1\bin";%PATH%.

On some unix like environment it should be very similar but use export PATH=<path to jdk>/bin:$PATH instead.

You want to make sure that the java command you are running is the one in that bin folder for the correct jdk.

cyrillemidingoyi commented 6 years ago

Thanks SpencerPark. It's working now.

rockie-yang commented 5 years ago

On macos. It solved for me by adding this to ~/.bash_profile

export JAVA_HOME="$(/usr/libexec/java_home)"
export PATH=$JAVA_HOME/bin:$PATH

If there is specific version like to use

export JAVA_HOME="$(/usr/libexec/java_home -v 11)"
export PATH=$JAVA_HOME/bin:$PATH