Welcome to this Blog. I am Software Engineer and work for Zühlke Engineering AG in Bern. This is my private blog, in which I will post mainly about technical stuff like Software Engineering or IT related topics. The views expressed herein do not necessarily represent those of my employer.
Everybody, who’s working with Eclipse is knows the Content Assistant (better known as Code Completion). Just press CTRL + Space, and every possible piece of code gets completed.
But did you know, that Eclipse is also capable of using templates. Templates can be defined in Window – Preferences – Java – Editor – Templates.
For example, instead of typing the main function every time manually, just type main and press CTRL + Space, choose the template main and press Enter. The whole main method is created.
Interesting default templates are:
sysout: creates a System.out.println() entry
runnable: creates a complete Runnable inner class
public_method: template for a public method (same with private, default, and so on)
Of course, you also can define your own template. E.g. for an EJB 3.0 stateless or message-driven bean!
In some cases, ANT has it’s limitations. For example, it is not really easy to create an if-else structure or a for-loop. For this reason, a few people started long time ago the Ant-Contrib project. Just download it and put the jar file in the lib folder of the project. Then, just at following line to the build file:
<taskdef resource="net/sf/antcontrib/antcontrib.properties"></taskdef>Now, you can start using constructs like if, foreach and combine these tasks with usual ANT tasks. Here a little example:
with antcontrib:
<target name="theultimateconditionmachine"> <if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="property foo is bar" /> </then> <else> <echo message="property foo is not bar" /> </else> </if> </target>
without antcontrib:
if you want to perform the same task with ant, you need to create 4 (!) ant targets:
<target name="noway"> <antcall target="conditionIf"/> <antcall target="conditionElse"/> </target> <target name="conditionDef"> <condition property="conditionIsTrue"> <equals arg1="${foo}" arg2="bar"/> </condition> </target> <target name="conditionIf" depends="conditionDef" if="conditionIsTrue"> <echo message="property foo is bar"/> </target> <target name="conditionElse" depends="conditionDef" unless="conditionIsTrue"> <echo message="property foo is not bar"/> </target>
Some months ago, I wrote an article for accessing an EJB Sessionbean from a C# client. Just have a look.
Ever wondered, how you can force a team to use same code style and same code convention?
If you use Eclipse, there is a simple solution. Just install these two plug-ins und the live will be easier
- Checkstyle
Used to check the layout of the code. Do all methods have it’s Javadoc? Has the file the company header? Can be easily used in Eclipse and with Ant.
enable Checkstyle on a project:
run Checkstyle (could also be done by ANT):
check out the warnings on the left border:
- FormatOnSave
Eclipse plug-in, which formats the code on every save. Simply install this plug-in on the Eclipse installation of every team member and the code is now always in correct format. Just don’t forget to define the right format template on each installation.

OI = Organize Imports (on save)
SM = Sort Members (on save)
CI = Correct Identation (on save)
F = Format (on save)
« Newer Posts
