Configure working directory of Scala worksheet -
i working directory scala worksheet (and scala interpreter) eclipse project path rather eclipse installation directory. how can (non programmatically) achieve that?
i know can use system.setproperty("user.dir", "...")
, imho not belong in code. further, not seem work:
object scratchws { system.setproperty("user.dir", "c:\\") //> res0: string = c:\adt-bundle-windows-x86_64-20130219\eclipse new file("putty.exe").exists() //> res1: boolean = false new file("c:\\putty.exe").exists() //> res2: boolean = true }
as of scala worksheet 0.2.1 not possible control worksheet working directory.
for security reasons, once jvm running, not (directly) possible change jvm's working directly. see changing current working directory in java? details.
therefore, practice specify qualified paths, or specify relative paths qualified "anchor point".
here's hack came getting such "anchor point" in scala worksheet
object worksheetprojectdirhack { // yuck.... see: https://github.com/scala-ide/scala-worksheet/issues/102 import properties._ val pathsep = proporelse("path.separator", ":") val filesep = proporelse("file.separator", "/") val projectdir = javaclasspath.split(pathsep). filter(_.matches(".*worksheet.bin$")).head. split(filesep).dropright(2).mkstring(filesep) val otherprojectfile = new file(projectdir, "src/main/resources/data.bin") }
it works taking advantage of the existence of .worksheet/bin
directory created in eclipse project directory , appended scala worksheet classpath.
Comments
Post a Comment