Question

I'm developing a JLine based application, which I'd obviously like to test as I develop.

JLine is a handy library which provides interactive console functionality to JVM applications.

JLine doesn't work in the Intellij console, probably because they've appropriated the tab key for their own nefarious needs, and what I want to test is tab-completion, because I'm implementing some tab-completed commands.

I drop to the SBT console, and try run-main Example simple, but I throws an Exception because there are now two jline libraries in the classloader - my one, and the one that SBT uses so the application explodes while loading JLine library (Singletons are evil)....

Sigh... Twiddle about at the SBT console for a bit, and discover I can run:

> show runtime:managed-classpath

[info] List(Attributed(/home/bryan/.sbt/boot/scala-2.10.0/lib/scala-library.jar), Attributed(/home/bryan/.ivy2/cache/org.parboiled/parboiled-scala_2.10/bundles/parboiled-scala_2.10-1.1.5.jar), Attributed(/home/bryan/.ivy2/cache/org.parboiled/parboiled-core/bundles/parboiled-core-1.1.5.jar), Attributed(/home/bryan/.ivy2/cache/jline/jline/jars/jline-2.10.jar))

I know I can parse that list, obviously spaces or commas would be a perfectly viable separator but Scala developers don't seem to be wired that way...

But SBT only seems to parse that command when I'm in it's console, if I execute that command from the actual, UNIX, console, like so:

% sbt show runtime:managed-classpath
[info] Loading project definition from /common/moon_excel/project
[info] Set current project to moon_excel (in build file:/common/moon_excel/)
[error] Not a valid command: show (similar: shell)
[error] Expected whitespace character
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: show (similar: show-timing)
[error] show

I'm trying to automate the process for when I've got 100 jars on the classpath (slight exaggeration), any suggestions?

Was it helpful?

Solution

sbt 0.13 (currently at RC3) moves JLine classes so that they aren't visible to user code. This should avoid conflicts with your code. Note that JLine currently leaks class loaders, so you may get PermGen errors after several runs.

You can use export runtime:fullClasspath in 0.13 to export a standard classpath string. In earlier versions, you can write a custom task. See also plugins like sbt-start-script, which generate a run script for you.

Finally, if possible, consider writing tests that don't need an interactive prompt. For example, sbt itself has some ScalaCheck properties for its completion library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top