Archive for August, 2009

Aug 31 2009

JUnit 4 error: reference to assertEquals is ambiguous

Published by under Java,JUnit,Testing

This is a somewhat confusing compilation failure that sometimes happen when you write unit tests using JUnit 4. This is an example code snippet that produces this error (result.getValue() returns an Integer object): assertEquals(12345, result.getValue()); And when you try to compile your project it produces a compilation error like this: /projects/myapp/src/test/java/org/myapp/[88,8] reference to assertEquals is […]

4 responses so far

Aug 26 2009

Spring XML and defining end of line characters in a bean property

Published by under Java,Spring,XML

If you need to define and end of line character (EOL) like n in your Spring XML files in a bean property you can’t do this <bean id=”some-bean-id” class=”some-class”> <property name=”my-property-name” value=”n”/> </bean> This simply wont work. You’ll end up with a backslash followed by the letter n. What you have to do is to […]

No responses yet

Aug 26 2009

Maven, Log4j and javax.jms

Published by under Java,Logging,Maven

Log4j version 1.2.15 added features which has new dependencies on sun and javax packages. When you try to build your project using Maven and log4j 1.2.15 you will see this: [INFO] Unable to find resource ‘com.sun.jmx:jmxri:jar:1.2.1’ in repository central ( [INFO] Unable to find resource ‘com.sun.jdmk:jmxtools:jar:1.2.1’ in repository central ( [INFO] Unable to find resource […]

No responses yet

Aug 24 2009

svn: Inconsistent line ending style when trying to commit a binary file

Published by under SCM,Subversion / SVN

If you get this error message “svn: Inconsistent line ending style” when trying to commit a binary file into your SVN repository then Subversion probably thinks that your file is a text file. First verify your file with: svn proplist <your-file> If the result contains svn:eol-style but you know that your file is a binary […]

One response so far

Aug 21 2009

How to read environment variables in Java

Published by under Java

You can set environment variables or pass them in using the -Dvariablename syntax SET logfile=/location/to/my/log/file.log or java -Dlogfile=/location/to/my/log/file.log HelloWorld When you want to access these environment variables from your Java source file you can use Java 1.5 and newer: String logfileLocation = System.getenv(“logfile”); Java 1.4 and older: String logfileLocation = System.getProperty(“logfile”);

No responses yet

Aug 19 2009

What jar file does a Java class belong to?

Published by under Java

I found this very useful web site that allows you to search what JAR file a specific Java class belongs to. This has proven quite useful to me over the last couple of days when I had to deal with NoClassDefFoundError and ClassNotFoundException problems. You can just enter the name of the class or JAR […]

One response so far

Aug 04 2009

Mockito an alternative to JMock

Published by under Java,Testing

I’ve used JMock for quite some time and I’ve found it to be a great and very useful mocking framework for unit testing. I was never quite happy with the syntax though; especially the part where you specify expectations.  Here’s a JMock snippet illustrating an expectation and a return value from a mocked object context.checking(new […]

2 responses so far

Aug 03 2009

Entourage taking over my harddrive

Published by under OS X / Apple OS

I noticed that I had almost no space left on my MacBook and I couldn’t see a good reason why I would have so little space left. In Windows I used an excellent application called WinDirStat to find out what was wasting space on my harddrive, and I was glad to see that there’s a […]

No responses yet

Aug 03 2009

Java and the current work directory

Published by under Java

I spent some time looking this up and hopefully I will save someone else time on this. The current work directory for an application in Java is stored in the system property “user.dir”. This is the default directory that you application will write files to if you don’t specify an absolute file location. You can […]

No responses yet

Aug 02 2009

Maven pom.xml structure

Published by under Maven

I wanted to see the full Maven pom.xml structure and I found the following page on the Maven web site that contains all the elements and descriptions.

No responses yet

Older Entries »