Aug
21
2009
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");
Aug
19
2009
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 file your looking for and the site will display the result.
http://www.findjar.com/index.jsp
Aug
04
2009
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 Expectations() {{
oneOf (department).employees(); will(returnIterator(employees));
}});
In Mockito the equivalent code would look like this
when(department.employees()).thenReturn(employees);
I find the Mockito syntax to be easier to write and understand. I’ve seen fellow developers implement JMock expectations in a way where they actually didn’t perform a useful test, and I think the sometimes confusing syntax of JMock was the reason. I’m not dismissing JMock as an inferior mocking framework, but I do think that the learning curve is a bit steeper. If you haven’t used Mockito yet I encourage you to take a look at it.
Aug
03
2009
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 similar app for OS X called Disk Inventory X. Both of these free and excellent applications shows you a graphical tree map that makes it easy to see what is using up your disk space. In my case it turned out to be Entourage which due to frequent crashes had led to multiple copies of the Entourage database. I deleted several copies of the database and recovered a lot of space.
Disk Inventory X: http://www.derlien.com/
Location of Entourage files: http://www.entourage.mvps.org/path/index.html#ent_db
Aug
03
2009
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 access it using this Java syntax:
String userDir = System.getProperty("user.dir");
Aug
02
2009
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.
http://maven.apache.org/ref/2.2.0/maven-model/maven.html
Aug
02
2009
I had a need to identify what process ID (PID) on my MacBook running OSX that had a specific IP address and port open so that I could kill it. It took me a while to figure this out but eventually I found something that worked.
lsof -i
This will show you
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Microsoft 280 someuser 15u IPv4 0x8862e64 0t0 TCP *:3546 (LISTEN)
...