Press enter to see results or esc to cancel.

JUnit 4 error: reference to assertEquals is ambiguous

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/MyTest.java:[88,8] reference to assertEquals is …

Continue reading

Maven, Log4j and javax.jms

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 (http://repo1.maven.org/maven2) [INFO] Unable to find resource ‘com.sun.jdmk:jmxtools:jar:1.2.1’ in repository central (http://repo1.maven.org/maven2) [INFO] Unable to find resource …

Continue reading

How to read environment variables in 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”);

Continue reading