I have searched the web and have found several people asking about a Scrapbook feature (as in Eclipse Scrapbook) but could not find that a feature request has been filed.
The scrapbook is a page that can be attached to a project in the IDE and can be used to evaluate or test run java code. A very handy feature indeed.
The Evaluate window that appears when debugging the project is similar, though the UI is clumsy for writing complex expressions, and they are not persisted. This is also not available without starting the app, whereas e.g. with jrunscript you can interactively check various functions so long as they require no special services to be running.
This feature could surely be implemented as an add-on plugin. I am not sure what the best way to parse and evaluate Java code interactively is; you probably need to use JSR 199 to actually compile a block somehow, as if it formed a method body.
I haven't tried Eclipse' Scrapbook, but I do not think this has anything to do with debugger.
IMHO it can be implemented either by compiling the user-written code in a dedicated class and running that, or by interpreting the code (in a similar way that is done by debugger, but instead of delegating the execution through debugger, run it in a special class loader).
IMHO this is about execution, not debugging.
Perhaps it would be nice if one can also debug the code snippet, but the main concept needs to be implemented in Java project, I think.
The above link is to a download page for a beginner's tutorial on java and Eclipse. The tutorial on the Scrapbook is in lesson #3, unfortunately all lessons must be downloaded in order to watch it. I think the Scrapbook feature would make a very nice enhancement to Netbeans. Very handy for evaluating code snippets without having to build an entire class or even a method. Perhaps more valuable to a beginner (again) like me than to an experienced developer.
I would encourage anyone who is interested in this feature to download and watch lesson #3 of the above tutorial.
here is the help page from eclipse for this feature:
and here is another useful link:
what is not clear from these links, though, is that this is not only an expression evaluator. if you attach a scrapbook page to an eclipse project, you can run things related to the classes in that project from the scrapbook: instantiate an object, call its methods, call a main method etc.
it would be terrific to have something this useful in eclipse!
(erratum to comment #4)
> it would be terrific to have something this useful in *netbeans*!
Having this feature is the current time saver tool holding me back from totally switching to Net beans IDE.
More votes please.
(In reply to comment #2)
> compiling the user-written code in a dedicated class and running that
That is fine and probably not too hard; requires nothing specifically from the project system, just a ClassPath context from GlobalPathRegistry (EXECUTE).
The hard part would be displaying the object inspector on results as the Eclipse scrapbook does. Of course this is not absolutely necessary - you could just display the toString() of each result - but a key feature. In NB this GUI currently exists only in the debugger and is not available for reuse.
I committed contrib #ce13cee71654 with a very rudimentary scrapbook feature - no Java syntax highlighting or code completion, run blocks only (no expression evaluation or mixing imports with statements), no object inspector, no support for alternate boot classpaths, etc. But it does work to keep track of some sample code snippets and run them against the project's classpath (use println(...) to display results).
FYI: Geertjan took jglicks code and created a proof-of-concept plugin out of it
Perhaps this could be improved and integrated?