JDeveloper code templates
When you write a lot of code, no matter what sophisticated framework you use, there are pieces of code that you end up writing over and over again (especially when using Java). Writing logging code in Java is a good example. A common pattern is to initialize a static logger variable in every class you want to log something. Fortunately, JDeveloper has a feature called “Code Templates” that can make your life a lot easier! I have seen several blogs that explain how to use Code Templates for logging code (I saw one from as early as 2006; the feature itself has actually been available since 2004!). But still a lot of people are not aware of this feature (or perhaps simply forget to use it).
That is why I created the simplest logging code templates ever. Download the Code Templates XML file and import them into JDeveloper, see screenshot below (note that you cannot import the file from a location with a space in the path, a known JDeveloper issue).
Now simply enter “log” followed by Ctrl-Enter at the start of the class to create a static logger variable.
After that, simply enter “log” followed by Ctrl-Enter anywhere you want to log something.
That is easy, right? A slightly more complicated example is the template: “lvar”. With this template you can easily log the name and value of a variable. Simply enter “lvar” followed by Ctrl-Enter and then you can choose the variable to log (currently does not work for primitive types).
Remember that code templates are not limited to logging code (or to Java code)! Whenever you find that you have to type the same thing (or similar things) over and over again you could probably create a code template that does it for you.
This entry was posted by Paco van der Linden on May 1, 2013 at 5:36 pm, and is filed under Devel. + PL/SQL tools, Java, Oracle Development Tools, Software Development, Tools, Web/Java. Follow any responses to this post through RSS 2.0.You can skip to the end and leave a response. Pinging is currently not allowed.
- The AMIS Summary of Oracle OpenWorld 2013 is available for download – 60-page white paper
- On the integrity of data in Java applications – presentation from JFall 2013
- Book Review of Building Modular Cloud Apps with OSGi by Bert Ertman and Paul Bakker (last edit: 25th October)
- Java 8 – Collection enhancements leveraging Lambda Expressions – or: How Java emulates SQL
- OOW13: summarizing one week and 2000 sessions in 3 hours and a bit – the yearly AMIS OOW Review session – 10th October
- JavaOne 2013: (Key) Notes of a conference – State of the Java platform and all the roadmaps
- OOW13 and JavaOne 13: Notes from a Conference – Part Two
- OOW13 and JavaOne 13: Notes from a Conference – Part One
- JDeveloper 12c & ADF 12c: Launch of the next generation
- Getting started with Java EE 7 – Hands on in 10 minutes