Filtered Resources in Maven

Maven has some really great features. One of them is filtered resources. Basically, if you use Maven for some time, I’m sure you know what by default everything you put in src/main/resources will be added to the classpath in the resulting artifact (e.g. in the WEB-INF/classes for a *.war archive.) Putting resources in this location is a common way of adding Java properties file to your project. Now what is interesting: you can use Maven variables in those resource files and they can be swapped into final value during the process-resource phase....

October 14, 2012 · 2 min

Inject Java Properties in Java EE Using CDI

The aim of this post is to show you how, using CDI, you can inject Java properties entries (those in *.properties files) directly into your Java class. This is somewhat similar to the Spring’s @Value annotation I needed in my plain Java EE project. The whole code can be found on GitHub so feel free to clone it, use it or make any changes you like. Context Ok, so basically in a Java EE environment we already have a way to define some properties that are deployment-specific – it’s the <env-entry> element in the descriptor....

June 17, 2012 · 12 min

Properties -- be aware the evil whitespaces!

Just a letter to my future self: When you use Properties and creates the entries, remember to avoid the whitespaces. The properties are inserted as-they-are, so no trimming occurs. It might sound trivial, but it wasted at least an hour of my time, while I was searching for a bug in a totally wrong department… Pure evil: Properties p = new Properties; p.put("java.naming.factory.initial", " org.apache.openejb.client.LocalInitialContextFactory");

May 19, 2011 · 1 min

JavaBeans -- getters with Boolean type

When you want to create a boolean property in a Java Bean (let’s name it visible), you most likely would want to use a boolean type variable and create accessors for it. Well, if you use a boolean primitive it is allowed to create a getter in one of two manners: public boolean getVisible() or public boolean isVisible() Notice that the second option is only allowed when your property is a boolean primitive....

January 13, 2011 · 1 min

Automatically build number generation in ANT

I wanted to find some solution to a problem of automatic generation of build numbers/version identifiers using an ANT. I figured out that I can achieve it in the following way: <target name="numerate.version" description="Generates version number and sets it in Client properties file."> <tstamp> <format property="build.time" pattern="yy-MM-dd_hh:mm" unit="hour" /> </tstamp> <buildnumber file="build.number" /> <property name="version.code" value="${build.version}/${build.time}/${build.number}" /> <echo>Version: ${version.code}</echo> <replaceregexp file="${client.commonsi18n.pl}" match="(version[ \t]*=[ \t]*)+.*$" byline="true" replace="\1${version.code}" /> </target> A short description what is going on:...

January 9, 2011 · 1 min