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?
Jesse's and Geertjan's plugin is a good start, but it doesn't seem to handle anything more than simple expressions.
For instance, I often find myself writing a little java program to interpret some file content (mostly because I'm much more familiar with Java syntax than with shell scripting). The way I have to do it now is: (1) create a class "Project->New->New Java Class", (2) manually type in its main(), (3) type in my code, (4) Right-click->Run File.
The current plugin doesn't seem to appear import statements, so how would I write any snippet dealing with IO? I can't see a way.
In my simple world, a "scrap book" would be a partially editable .java file (similar to "forms" java files the GUI builder creates) with an editable "imports" area and an editable "content" area that forms the body of "main()". Optionally, there's be a "Run" button at the bottom of the panel (but the current rightclick->Run File is sufficient).
(In reply to twolf2919 from comment #10)
> Jesse's and Geertjan's plugin is a good start, but it doesn't seem to handle
> anything more than simple expressions.
> For instance, I often find myself writing a little java program to interpret
> some file content (mostly because I'm much more familiar with Java syntax
> than with shell scripting). The way I have to do it now is: (1) create a
> class "Project->New->New Java Class", (2) manually type in its main(), (3)
> type in my code, (4) Right-click->Run File.
To be clear, I understand that I could just always create a "Scratch" java file at the root of my project whenever I create a new Project and use it whenever I want to do something like the above. I've done that in the past. The problem is that the project source is under source control and I always have to be vigilant that I don't accidentally commit this "Scrap" java file with the rest of my changed project sources. A few times I wasn't.
Also, I see that the original intent of this enhancement request was merely to support "expression evaluation" - which Geertjan's plugin does do - so maybe I should be filing my own enhancement issue - but since several others' comments expressed a desire for something more than just expression evaluation, I'll keep it here for now.
I currently use an ARM based embedded system for my programming needs, I found that NetBeans works flawlessly. Eclipse does not even offer a version of their IDE in ARM newer than 3.8. After using Eclipse I found a lot of features that NetBeans offers and found the transition to be quite painless. There are features I like better on NetBeans, but no ScrapBook, at least one that works. I found a plugin that installs and seems to function, but no snippets run, not even the simplest System.out.println("Hello World"); Everything gives an error [/tmp/_.java:1: warning: '_' used as an identifier] . A code snippet evaluator is handy for learning the java library and testing parts of your program, it is a shame that NetBeans does not have something similar.
(In reply to jessgwiii from comment #12)
> I currently use an ARM based embedded system for my programming needs, I
> found that NetBeans works flawlessly. Eclipse does not even offer a version
> of their IDE in ARM newer than 3.8. After using Eclipse I found a lot of
> features that NetBeans offers and found the transition to be quite painless.
> There are features I like better on NetBeans, but no ScrapBook, at least one
> that works. I found a plugin that installs and seems to function, but no
> snippets run, not even the simplest System.out.println("Hello World");
> Everything gives an error [/tmp/_.java:1: warning: '_' used as an
> identifier] . A code snippet evaluator is handy for learning the java
> library and testing parts of your program, it is a shame that NetBeans does
> not have something similar.
@jessgwiii: Please do not change the version property of issues. This property states when the issue has been filed. Reset to original value 6.x
If the plugin, you use, does not work, please contact the author of the plugin and report the bug!