Skip to content

Commit f07ca0f

Browse files
committed
Add "How to add your own JARs"
1 parent 439d016 commit f07ca0f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,28 @@ To connect a Scala REPL console to a process:
4848
scalive <pid>
4949
```
5050

51-
## How it works
51+
## How to add your own JARs
52+
53+
Scalive only automatically loads `scala-library.jar`, `scala-compiler.jar`, and
54+
`scala-reflect.jar`. If you want to load additional classes in other JARs, first
55+
add the JAR to the system class loader:
56+
57+
```
58+
val cl = ClassLoader.getSystemClassLoader.asInstanceOf[java.net.URLClassLoader]
59+
val searchDirs = Array("/dir/containing/the/jar")
60+
val jarbase = "mylib" // Will match "mylibxxx.jar", convenient when there's version number in the file name
61+
scalive.Classpath.findAndAddJar(cl, searchDirs, jarbase)
62+
```
63+
64+
Now the trick is just quit the REPL console and open it again. You will be able
65+
to use your classes in the JAR as normal:
66+
67+
```
68+
import mylib.foo.Bar
69+
...
70+
```
71+
72+
## How Scalive works
5273

5374
Scalive uses the [Attach API](https://blogs.oracle.com/CoreJavaTechTips/entry/the_attach_api)
5475
to tell the target process to load an [agent](http://javahowto.blogspot.jp/2006/07/javaagent-option.html).

0 commit comments

Comments
 (0)