• Stars
    star
    198
  • Rank 189,527 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Connect a Scala REPL to running JVM processes without any prior setup

Scalive

This tool allows you to connect a Scala REPL console to running Oracle (Sun) JVM processes without any prior setup at the target process.

View demo video on YouTube

Download

For Scala 2.12, download scalive-1.7.0.zip.

For Scala 2.10 and 2.11, download scalive-1.6.zip.

Extract the ZIP file, you will see:

scalive-1.7.0/
  scalive
  scalive.bat
  scalive-1.7.0.jar

  scala-library-2.12.8.jar
  scala-compiler-2.12.8.jar
  scala-reflect-2.12.8.jar

scala-library, scala-compiler, and scala-reflect of the correct version that your JVM process is using will be loaded, if they have not been loaded yet. The REPL console needs these libraries to work.

For example, your process has already loaded scala-library 2.12.8 by itself, but scala-compiler and scala-reflect haven't been loaded, Scalive will automatically load their version 2.12.8.

If none of them has been loaded, i.e. your process doesn't use Scala, Scalive will load the lastest version in the directory.

For your convenience, Scala 2.12.8 JAR files have been included above.

If your process uses a different Scala version, you need to manually download the corresponding JARs from the Internet and save them in the same directory as above.

Usage

Run the shell script scalive (*nix) or scalive.bat (Windows).

Run without argument to see the list of running JVM process IDs on your local machine:

scalive

Example output:

JVM processes:
#pid	Display name
13821	demos.Boot
17978	quickstart.Boot

To connect a Scala REPL console to a process:

scalive <process id listed above>

Just like in normal Scala REPL console, you can:

  • Use up/down arrows keys to navigate the console history
  • Use tab key for completion

How to load your own JARs to the process

Scalive only automatically loads scala-library.jar, scala-compiler.jar, scala-reflect.jar, and scalive.jar to the system classpath.

If you want to load additional classes in other JARs, first run these in the REPL console to load the JAR to the system class loader:

val cl            = ClassLoader.getSystemClassLoader.asInstanceOf[java.net.URLClassLoader]
val jarSearchDirs = Array("/dir/containing/the/jar")
val jarPrefix     = "mylib"  // Will match "mylib-xxx.jar", convenient when there's version number in the file name
scalive.Classpath.findAndAddJar(cl, jarSearchDirs, jarPrefix)

Now the trick is just quit the REPL console and connect it to the target process again. You will be able to use your classes in the JAR normally:

import mylib.foo.Bar
...

Note that :cp doesn't work.

How Scalive works

Scalive uses the Attach API to tell the target process to load an agent.

Inside the target progress, the agent creates a REPL interpreter and a TCP server to let the Scalive process connect and interact with the interpreter. The Scalive process acts as a TCP client. There are 2 TCP connections, one for REPL data and one for tab key completion data.

Similar projects:

Known issues

For simplicity and to avoid memory leak when you attach/detach many times, Scalive only supports processes with only the default system class loader, without additional class loaders. Usually they are standalone JVM processes, like Play or Xitrum in production mode.

Processes with multiple class loaders like Tomcat are currently not supported.

More Repositories

1

xitrum

Async and clustered Scala web framework and HTTP(S) server
Scala
447
star
2

glokka

Library to register and lookup actors by names in an Akka cluster
Scala
56
star
3

scaposer

GNU Gettext .po file loader for Scala
Scala
38
star
4

scala-xgettext

Scala compiler plugin that acts like GNU xgettext command to extract i18n strings in Scala source code files to Gettext .po file
Scala
25
star
5

xitrum-new

Empty Xitrum project skeleton, like the one created by "rails new"
Scala
21
star
6

xitrum-demos

Demos for Xitrum
Scala
19
star
7

xitrum-package

SBT plugin for collecting dependency .jar files for standalone Scala programs
Scala
18
star
8

comy

Simple URL shortener using Xitrum and MongoDB
Scala
16
star
9

sclasner

Scala classpath scanner
Scala
10
star
10

xitrum-doc

Xitrum Guide Book and presentations about Xitrum
CSS
8
star
11

RhinoCoffeeScript

coffee-script.js precompiled to JVM .class file by Rhino
Java
7
star
12

agent7

Java agent to reload .class files; it uses file watch API available in Java 7+
Java
5
star
13

xitrum-scalate

Template engine for Xitrum based on Scalate
Scala
4
star
14

xitrum-hazelcast

Cache and server side session store for Xitrum, based on Hazelcast
Scala
3
star
15

xitrum-multimodule-demo

http://groups.google.com/group/xitrum-framework/browse_thread/thread/7588995934854a56
Scala
2
star
16

xitrum-ko

Knockout.js plugin for Xitrum
Scala
1
star
17

xitrum-scalatags

Template engine for Xitrum based on ScalaTags
Scala
1
star
18

xitrum-tictactoe

Tictactoe web game - Demo for Akka and Xitrum
Scala
1
star
19

xitrum-framework.github.io

Source code of the home page of Xitrum framework
HTML
1
star