Tag Archives: java

Netbeans’ tomcat log file path

      No Comments on Netbeans’ tomcat log file path

Spawning a tomcat server instance from within Netbeans is really handy for rapid Java Servlet or JavaServer Pages application development. Since log levels are usually quite verbose during development, logs tend to pile up. So you might want to clean out the log directory from time to time. Or maybe you just want to go through one of those logs… Read more »

Convert a JAR file into a Linux executable

      No Comments on Convert a JAR file into a Linux executable

With Java programs it’s quite common to combine several classes into one JAR archive. Java libraries are typically distributed this way as well. On Linux platforms, people are quite used to using command line programs, but sometimes it’s handy to distribute a java program as an executable file that can be run by a simple double-click instead of opening a… Read more »

Run JUnit test from the command line

      No Comments on Run JUnit test from the command line

JUnit tests can be run easily from within your IDE. Every remotely up to date IDE has some built-in view that gives nice visual feedback, usually red or green indicators. But of course it is also possible to invoke your tests from the command line. A simple example: A very nice article on JUnit testing by Lars Vogel can be… Read more »

Specifying file encoding when writing dom Documents

Assumed, we got a fully parsed org.w3c.dom.Document: Just using LSSerializer‘s writeToString method without specifying any encoding will result in (rather impractical) UTF-16 encoded xml file per default will output Unfortunately, specifying an encoding isn’t trivial. Here are two solutions that don’t require any third party libraries: 1. Using org.w3c.dom.ls.LSOutput 2. Using javax.xml.transform.Transformer

Multiple main methods in a single jar archive

A Java archive file usually holds a manifest file that specifies the main class to start when you invoke java -jar jarfile. It’s something similar to this: When you distribute your jar file, a user can simply execute it (possibly even with a double click) without knowing anything about your package structure or location of the main class. But what… Read more »

Duplicate log4j output lines

      No Comments on Duplicate log4j output lines

Ever seen duplicate lines in your log4j output? Maybe something like this: Well, the obvious cause is probably duplicate loggers your log4j configuration: As the properties are inherited from the root logger, this is telling log4j that all quartz-classes should send their log to the DefaultConsoleAppender (which the root logger is doing anyway). So we simply have to remove the… Read more »

Efficiently searching the Java API

      No Comments on Efficiently searching the Java API

Since Sun’s API search is a real pain in the arse and even DocWeb doesn’t allow you to quickly search the Java API, this firefox plugin is a substantial improvement: https://addons.mozilla.org/en-US/firefox/addon/60675/ It basically redirects the search query to Google’s “I’m Feeling Lucky” feature to search Java’s API for the class information. Together with Second Search querying the Java API is… Read more »

Implementing equals() the right way

      No Comments on Implementing equals() the right way

At first sight, implementing equals() doesn’t seem fairly hard. Unfortunately, it turns out that writing a correct equality method is surprisingly difficult: http://java.sun.com/javase/6/docs/api/java/lang/Object.html The equals method implements an equivalence relation on non-null object references: It is reflexive: for any non-null reference value x, x.equals(x) should return true. It is symmetric: for any non-null reference values x and y, x.equals(y) should… Read more »

Using a HashSet in a thread-safe manner

      4 Comments on Using a HashSet in a thread-safe manner

Thread safety is a very hot topic for Java programmers right now. But I’ve seen quite a few folks using the rather complex collections from java.util.concurrent when they actually needed just a thread-safe implementation of a Set. Of course, the HashSet implementation is non-thread-safe: http://java.sun.com/javase/6/docs/api/java/util/HashSet.html Note that this implementation is not synchronized. If multiple threads access a hash set concurrently,… Read more »

Java plugin for Firefox 3.6

      1 Comment on Java plugin for Firefox 3.6

Since Mozilla dropped support on OJI (Open Java Virtual Machine Integration), the classic java plugin file javaplugin-oji.so doen’t work anymore for Firefox versions >3.6. Starting in Firefox 3.6, Mozilla will only support the standard NPAPI and NPRuntime interfaces. However, a ‘Next-Generation Java plugin’ (that’s what Sun calls it) is available in Java version 6 update 10 or newer and supports… Read more »