Archive for the ‘Java’ category

JSQLiteManager v0.1.1 released

June 25th, 2010

JSQLiteManager is a SQLite database manager written in Java.
I’ve looked for a decent (and free) database manager for SQLite for a while, but hadn’t found anything. Each app had it’s own little annoyances like plainly crashing every few actions you do, or the query view that only shows 1 column (you had to click the scrollbar to move forward and back through the columns..).

So I felt that I should make a decent free SQLite database manager (or to be honest I was so annoyed that I couldn’t find anything decent that I felt forced to make something decent myself).

» Read more: JSQLiteManager v0.1.1 released

Java doesn’t support inheriting twice from the same interface with a different generic parameter

June 22nd, 2010

I created this:

public class Observable <T> {
	private List<Observer<T>> observers = new ArrayList<Observer<T>>();

	public void addObserver(Observer<T> observer){
		observers.add(observer);
	}

	public void removeObserver(Observer<T> observer){
		observers.remove(observer);
	}

	public void removeAllObservers(){
		observers.removeAll(observers);
	}

	public void notifyObservers(Observable<T> observable){
		for(Observer<T> observer : observers){
			observer.update(observable);
		}
	}
}

And this:

» Read more: Java doesn’t support inheriting twice from the same interface with a different generic parameter

Automatically add library jar contents to executable jar with Netbeans

June 5th, 2010

Say you have a Java project in Netbeans with a library jar added.
In my case this was SQLiteJDBC, an SQLite JDBC driver for Java applications.

When you  build the project (“Clean and build project”) a folder ‘dist’ will be created with as contents:

  • Your executable jar file
  • A ‘lib’ folder with the jar files of your added libraries  inside

In your executable jar file (it’s actually a zip file, you can open it with Winrar for example) there is a folder called ‘META-INF’ with inside a file called ‘MANIFEST.MF’.

Class-Path: lib/sqlitejdbc-v056.jar

This line in ‘MANIFEST.MF’ makes sure that your executable jar file knows that the jar file for the SQLiteJDBC driver library is in ‘lib/sqlitejdbc-v056.jar’

Now, the problem for me was that I wanted a single executable, not an executable with some added library files.
With Java you can easily solve this problem by copying the contents of your library jars into your executable jar.
This means opening sqlitejdbc-v056.jar and opening the created executable jar with Winrar and dragging all the contents from the library jar to the executable jar.

Now, I’m quite lazy and I want that when I click the ‘Clean and Build’  button this all happens automatically.

» Read more: Automatically add library jar contents to executable jar with Netbeans