Archives for Java

Tuning Intellij Idea

First of all consider changing idea.vmoptions. idea.vmoptions is a text file with a list of JVM settings, it’s usually found in the bin folder in the Idea installation folder. This file can be open in any text editor. The following settings increase performance drastically on Sun JVM 1.6: -server -Xms128m -Xmx512m -XX:MaxPermSize=250m -XX:ReservedCodeCacheSize=64m -XX:+UseConcMarkSweepGC -XX:+AggressiveOpts [...]

Create self-sufficient JAR with maven

After getting stuck several times with maven assembly plugin I decided to make a note on how to create self-sufficient jar with maven. Self-sufficiency implies jar to include all the required dependencies so it can be started with java without specifying extra classpaths. <build> <plugins> <!– Packaging configuration –> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> [...]

context:annotation-config for StaticApplicationContext

For some reason I’m unable to use XML configuration for spring in the current project (and thus ClassPathXmlApplicationContext) – don’t ask me why So I’ve to specify the entire configuration in code (by using StaticApplicationContext.registerSingleton). The question is – how to make StaticApplicationContext work as if “annotation-config” is specified to make application context process annotated [...]

How to write and debug your own annotations processor.

This is a short but comprehensive guide on how to write and debug your own annotations processor (assuming you are using Java 6, should work on Java 7 as well). Create jar where your annotations processor will reside, say ann-proc.jar (Just define annotation processor class).You may want to add dependency to the JDK’s tools.jar in [...]

Ugly Netbeans font rendering on Ubuntu Linux

Netbeans fonts rendering may look ugly on the latest Ubuntu. The following configuration does the trick for me (file $netbeans/etc/netbeans.conf, see part in bold): # Options used by NetBeans launcher by default, can be overridden by explicit # command line switches: netbeans_default_options=”-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=lcd_hrgb” Checked with openjdk, it probably [...]

Spring and AspectJ

For those who uses Spring 3.0.5: Spring 3.0.5 doesn’t work with aspectjweaver 1.6.10+ due to AssertionError at org.aspectj.weaver.UnresolvedType.nameToSignature! E.g. if you use aspects in your spring config with, say, jdbc:initalize-database configuration clause, most likely you’ll get assertion error in your JUnit test what uses such a config. The possible workaround would be to switch to [...]

Restlet’s JAX RS lacks custom converters

I published earlier how to use Restlet framework with Spring over its JAX RS frontend. Unfortunately, there is no simple way to specify custom JSON converter for certain types, say java.util.Date (e.g. if you want to serialize it to ISO 8601-compatible string representation). In order to support that you need either to write a custom [...]

REST API how to: JAX RS + Restlet + Spring + Maven

Several days ago I needed to add REST API support to my app. I decided to pick Restlet framework for its simplicity and broad community. Besides the obvious simplicity and power of the restlet engine, restlet guys provided a bulk of libraries to help to integrate with Spring, JAX RS (a.k.a. JSR 311) and many [...]

Javascript snippet: “asUtfCodes” function

Sometimes I need to include escaped string sequence to my code (mostly for unit tests), because clearcase (VCS I forced to use by my current employer) chokes when it encounters UTF-8 -encoded source code. In order to make my life easier, I wrote a small function that transforms a given input string to it’s escaped [...]

JDO vs JPA

In short: when possible use JDO. Here is the rationale.