Open david-romano opened 5 months ago
You're using the magic correctly (%classpath <path>
).
The system property (System.getProperty("java.class.path")
) isn't updated because that is the app classpath for the kernel itself but the managed JShell's classpath is still updated. When you run code in a cell it is compiled and run with a different classpath set through the various magic commands.
If you are distributing class files (rather than a jar) then they should be in folders matching their package structure and the root path added with %classpath
.
e.g. with a class called HelloWorld
in package com.example;
located at /content/sample_data/com/example/HelloWorld.class
, then you can use it with the following:
%classpath /content/sample_data
import com.example.HelloWorld;
System.out.println(HelloWorld.class);
The system property (
System.getProperty("java.class.path")
) isn't updated because that is the app classpath for the kernel itself but the managed JShell's classpath is still updated. When you run code in a cell it is compiled and run with a different classpath set through the various magic commands.
Thanks for clearing that up! I'm guessing a distinction similar to the kernel/JShell one is why the output of HelloWorld
doesn't appear as cell output for a cell whose code is:
Runtime.getRuntime().exec("java /content/sample_data/com/example/HelloWorld");
but that's outside the subject of the current thread, so I'll try to raise the question separately. Thanks again for the help!
For context, I use this code:
(from this gist) to load IJava as the kernel in a Google Colab notebook, but no matter what I do, the classpath is always
Here's a Google Colab gist that shows how I'm using
%classpath
and how the classpath isn't updated afterwards.Am I using the magic incorrectly? I was hoping to be able import my own classes to use in a Google Colab notebook, but I can't get IJava to recognize them.
Thanks for any help!