Anton Arhipov is a Software Developer and Product Lead for JRebel, the productivity tool for Java developers. Anton’s professional interests include Java and related, programming languages and middleware. You can follow Anton on Twitter (@antonarhipov) and find him on LinkedIn (linkd.in/aarhipov). Anton has posted 18 posts at DZone. You can read more from them at their website. View Full User Profile

What’s Cool In IntelliJIDEA. Part III: External Tools

08.31.2011
| 4925 views |
  • submit to reddit

Although there is almost any kind of functionality available in IntelliJIDEA, either as a base functionality or via plugins, there's still a fraction of probability involved that you might want to do something that goes beyond the power of the IDE. For such rare cases you might want to take a look at External Tools in IntelliJ.

Just recently I've encountered such a case myself - I wanted to use a utility from the JDK, but in a more flexible way than just switching to command line and navigating to the correct location. My idea was that I should just press an arbitrary shortcut and get the result. So I decided to give External Tools a try.

 I use the javap - the java class file disassembler utility a lot when studying Java, in order to look at the bytecode. And although there's ASM plugin available for IntelliJ that can provide me with similar results, I still prefer to read the raw javap output.

To setup javap in Intellij as an External Tool go to Settings >> External Tools and press Add... . You can then define the location of the tool, the working directory, and the parameters.


The nice part of it is that IntelliJ provides some basic macros in order to dynamically resolve the parameters for the tool. So for javap it was enough to set $FileClass$ for the parameter, and $OutputPath$ as the working directory. And that's it - the tool is now ready for use.


You can also define a "group" which is then used to group the external tools in the popup menu. I use "jdk" as a group name for javap so here's what it looks after:


So that's cool but you might have noticed that it is not that comfortable to use - you have to right-click the file, navigate to "jdk" group, expand it, and only then can execute javap. Well, shortcuts to the rescue! Browse to Settings >> Keymap, and there you can define any sortcut for the tool. The nice part of it is that IntelliJ detects if you select a conflicting shortcut and notifies you.


One more tweak left to do. Once I press the shortcut that I've assigned to javap, the result of decompilation is printed out to the IDE console, which is just below the source code. But it would be more convenient to see it side by side. For that, it is possible to drag-and-drop the Run window to the side panel in IntelliJ so the result can be observed right next to the source I'm currently working with.


The only thing that is probably missing is syntax highlighting for the javap output, but that is probably too much to wish.

 

From http://arhipov.blogspot.com/2011/08/whats-cool-in-intellijidea-part-iii.html

Published at DZone with permission of its author, Anton Arhipov.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)