9

I like worksheets as an alternative to the REPL, but I keep implementing functions in the worksheet and then copying them back into the actual project. How do I import a package from the current project so that I can call those functions in the worksheet?

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
Arne Claassen
  • 14,088
  • 5
  • 67
  • 106
  • No, i tried the obvious, but overlooked a separate obvious mistake -- my worksheet was in a different project ( i had two worksheets and was using the wrong one, duuh) – Arne Claassen Oct 02 '12 at 01:34
  • Answer wasn't obvious to me either. The "._" bit escaped me. – justintime Apr 01 '13 at 20:13

1 Answers1

9

There is nothing special to do. Just do regular import of the packages you need in the worksheet. For instance:

import com.acme.myproject._

The worksheet is a totally regular source file, that simply gets evaluated in a fancy manner on save.

Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117
  • 6
    This is not working for me. I keep getting a notFound type error, however y I press Command and click on the class the Class opens, so on one hand it seems to "know" which class im refering to, and on the other it just wont run because the Class is not found – jstuartmilne Feb 01 '17 at 11:36
  • same problem here - my not-yet-published package `com.myCompany.myPackage`. If I want to use: `import com.myCompany.myPackage.MyPackage`: object `myPackage` is not a member of package `com.myCompany` – xhudik Apr 27 '21 at 09:21