Figure 9-3. The BeanShell class browser launched from the JDEE
You can also launch the class browser with the M-x jde-browse-class-at-pointcommand.
One other edit-time feature worth pointing out is the Code Generation item in the JDE menu. It has some great timesavers built-in, as shown in Table 9-7.
Table 9-7. Code Generation menu options
Keystrokes |
Menu option (M-x command) |
Action |
C-c C-v C-l(lowercase L) |
Println Wizard( jde-gen-println) |
Prompts for the contents to print and inserts a complete System.out.println( ) method for you. |
C-c C-v C-z |
Import Class( jde-import-find-and-import) |
Prompts for the (simple) class name to import and automatically adds the proper import line to the top of your file. |
C-c C-v i |
Implement Interface( jde-wiz-implement-interface) |
Prompts you for the name of the interface to implement. Adds any missing import statements (including dependent imports, such as imports required for method arguments). Provides commented skeletons for each of the methods in the interface. |
Other helpers are available from the JDE menu. Generate Get/Set Pairs in particular is great for working with JavaBeans design patterns. Just create your list of attributes and then run the wizard. It even checks to see if you already have an existing get/set pair. If you do, it notes that get/set pair as "existing" and keeps on trucking so you can use the wizard to update existing classes.
9.5.7 Compiling and Running with the JDEE
Compiling the current buffer can be done quickly with the C-c C-v C-ccommand. Any errors show up in the compilation buffer. That compilation buffer also allows you to navigate quickly to any errors that the compiler finds. Simply move your cursor to the error in question (using the normal motion commands) and hit Enter. You'll find yourself in the right file on the right line number. Very handy indeed.
Note that you can also run antbuilds with M-x jde-ant-build. Check out the JDEE documentation or the help for various jde-antvariables for more information.
Running a simple program that has its own main( )
method is easy: just press C-c C-v C-r. That command executes the current buffer (by opening an execution buffer named * fully.qualified.ClassName *
). Any output from the program shows in the buffer. You can move around in the buffer just as you would in a normal text buffer.
Of course, if you are working on anything other than a simple test class, you'll probably be in a package. Java's use of the classpaths rarely leaves room for being at the "bottom" of a package hierarchy. For example, in the package com.oreilly.demo
, you want to start execution from the same directory that contains the com directory, not from the demo directory that contains the actual Java files. Regrettably, the demo directory is the default.
You can edit the following variables to make executing in larger projects a bit more convenient:
jde-run-working-directory
The directory in which execution starts
jde-run-application-class
The fully qualified name of the class that contains the main( ) method to execute
With those values set, you should be able to run your application from any buffer, regardless of what directory the file you're editing happens to be in.
Another fun note about running your application through the JDEE: if any stack traces appear because of exceptions, you can navigate those traces by using the C-c C-v C-[and C-c C-v C-]commands (up and down, respectively). Again, Emacs makes it possible to manage quite a large portion of a development project all from one interface.
9.5.8 Debugging with the JDEE
A crucial element in any good IDE is its debugger. The JDEE allows you to stay in the Emacs realm while interacting with the jdbprocess. The JDEE also comes with its own debugger, the JDEbug application. JDEbug is more powerful but requires more setup effort.
Warning
Before we touch anything, you need to make sure that your classes are compiled with support for debugging. Otherwise, many things will appear broken when you run the debugger.
To add debug support when you compile, you run the javaccommand with the - goption. With the JDEE you can also use the variable jde-compile-option-debugto hold all the variations for debugging you like. If you customize this variable through Custom (see Chapter 10), just choose the "all" option for which debugging information to include. (Optionally, you can be more specific and select from the three types of debug information: Lines, Variables, and Source.)
We'll look at the jdbroute just to get you started. You can start the debug session by typing M-x jde-jdb. The same variables that control the starting directory and main application class are used for debugging purposes.
After you have launched the debugger, you can control the debug process in a number of ways.
• Interact directly with the jdbprocess in the *debug*
buffer. Here you can type any command that you would normally give when running jdb.
• Use the Jdb menu. You have all the usual debug options available: step into/over, continue, toggle breakpoint, and so on. This is a bit more limited than the first approach, but easier to manage if you're new to jdb.
• Use keyboard commands while you're in your source buffer. These commands are even more limited than the menu options, but give you really quick access to the most common tasks (namely stepping and break points). Table 9-8shows the commands that are available while you're in a source buffer.
Table 9-8. JDEE debugger controls
Keystrokes |
Menu item |
JDB command |
C-c C-a C-s |
Step Into |
step |
C-c C-a C-n |
Step Over |
next |
C-c C-a C-c |
Continue |
cont |
C-c C-a C-b |
Toggle Breakpoint |
stop in/stop at/clear |
C-c C-a C-p |
Display Expression |
print |
C-c C-a C-d |
Display Object |
dump |
Figure 9-4shows a simple application running in debug mode. Notice the small black triangle to the left of the Java source code in the upper buffer. That's the debug cursor that lets you know where you are in the file. It tracks the commands you issue, whether by directly entering jdbcommands, by menu option, or through the keyboard.
Figure 9-4. Debugging a Java application with jdb
9.5.9 Learning More about the JDEE
Clearly, there is a lot more to the JDEE than we can cover here. The package you download comes with some good documentation and several user guides for the basic JDEE and various options like the debuggers. The JDEE web site, at http://jdee.sunsite.dk, is a great source of information, too. As you would expect from an Emacs package, you can customize everything. Those customizations are stored in your .emacs file so you can tweak them by hand (or at least peek at them).
Читать дальше