Java program as a Windows service

11 02 2008

A few days ago, I used JSL for transforming a small Java program as a Windows service. The usage is really simple, define a class with static methods for starting and stopping the service. An example is the class TelnetEcho.java given with the sources of the library.

Then add the “jsl.jar” into the classpath, adapt the “jsl.ini” file to your needs and run “jsl.exe -debug” for testing the correct configuration of the service. This launches the service. Type “Ctrl-C” for stopping properly the service.

If everything is OK in this debug test, then you simply have to run “jsl.exe -install” in order to install the service. The name of the service is set in the jsl.ini file.

The service is then removed (if needed) with “jsl.exe -remove”.

Thanks Michael for this library.





Analyze your Java code

1 02 2008

Here is a list of tools that can help you analyze your code:

For more details, see http://dev.eclipse.org/blogs/seva/2008/02/01/java-code-structure-and-dependencies-analysis-tools-for-eclipse/





Graphical Java programs : Assertion `c->xlib.lock’ failed”

21 11 2007

If you are running linux and you had problems with some graphical Java programs (e.g. jconsole), then you could be interested in the following patch. The bug is known, but does not seem to have been solved correctly yet even if Novell indicates it as resolved. Each time I update java under OpenSuse 10.3, I must apply this patch.


#!/bin/sh
# S. Correia
# 2007 11 21
# A simple script to patch the java library in order
# to solve the problem with "Assertion 'c->xlib.lock' failed."
# see bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6532373
LIB_TO_PATCH=libmawt.so
for f in `find /usr/lib/jvm -name "$LIB_TO_PATCH"`
do
echo "Patching library $f"
sudo sed -i 's/XINERAMA/FAKEEXTN/g' "$f"
done





How to find the free disk space in Java?

25 09 2007

If you are a Java programmer, you may already have been asked this simple, stupide question: “how to find the free disk space left on my system?”. The problem is that the answer is system dependent. Actually, it is the implementation that is system dependent.
And until very recently, there was no unique solution to answer this question, although the need has been logged in Sun’s Bug Database since June 1997. Now it is possible to get the free disk space in Java 6 with a method in the class File, which returns the number of unallocated bytes in the partition named by the abstract path name. But you might be interested in the usable disk space (the one that is writable). It is even possible to get the total disk space of a partition with the method getTotalSpace().

But if you still use JDK 5, you’ll need to use an external library such as the Apache Commons and its FileSystem class.