Wednesday 29 February 2012

The finalize method

Before an object is garbage collected, the runtime system calls its finalize() method. The intent is for finalize() to release system resources such as open files or open sockets before getting collected.

Your class can provide for its finalization simply by adding a method in your class named finalize(). Your finalize() method must be declared as follows:
protected void finalize () throws throwable

The finalize() method is declared in the java.lang.Object class. Thus when you write a finalize() method for your class you are overriding the one in your superclass.

If your class's superclass has a finalize() method, then your class's finalize() method should probably call the superclass's finalize() method after it has performed any of its clean up duties. This cleans up any resources the object may have unknowingly obtained through methods inherited from the superclass.
protected void finalize() throws Throwable {
    . . .
    // clean up code for this class here
    . . .
    super.finalize();
}

Monday 27 February 2012

Run test via code

You can run your JUnit and JWebUnit tests from your own code. The class org.junit.runner.JUnitCore provides the method runClasses() which allows you to run one or several tests classes. As a return parameter you receive an object of the type org.junit.runner.Result. This object can be used to retrieve information about the tests.

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

class RunTests {

    public static void main(String args[]) {
        Result result = JUnitCore.runClasses(TestClass.class);
        for (Failure failure : result.getFailures()) {
            System.out.println("FAIL!: " + failure.toString());
        }
    }
}

http://www.vogella.de/articles/JUnit/article.html

Thursday 23 February 2012

Target "profile-j2ee" does not exist in the project

This is an error which you can get when attempting to Profile a project in NetBeans. A solution I found is;

"It seems that something has changed in project's build script, so the project 
is only partially modified for profiling, leading to the message you've 
provided. Probably the easiest way how to enable profiling again is to undo all 
project modifications and let the Profiler to integrate with the project again.

To do it, perform following modifications:

 - in build.xml, remove <import file="nbproject/profiler-build-impl.xml"/> line
 - in ./nbproject directory, remove profiler-build-impl.xml file
 - in ./nbproject/private, remove <data 
xmlns="
http://www.netbeans.org/ns/profiler/1" version="0.4"/> line
 - (optional) remove ./nbproject/private/profiler directory to remove all 
Profiler settings related to the project

Now after clicking the Profile (Main) Project action again, the Profiler 
notifies you about build script modification and profiling should work again."


From: 
http://netbeans.org/bugzilla/show_bug.cgi?id=73742

Wednesday 22 February 2012

copylibs doesn't support the "rebase" attribute

This can happen when a NetBeans 7.1 project opens a project with an older version of CopyLibs. The solution is;

- Tools->Libraries
- select the "Library location" that you want to fix (not the Global one)
- select the "CopyLibs Task"
- click the "Remove" button on the lower left corner
- click "Ok"

- In the project explorer right click on the "Libraries" virtual folder under
your project
- click "Add Library..."
- click the "Import" button
- select on "CopyLibs Task"
- click the "Import Library" button
- click the "Cancel" button

This can also happen the other way round i.e. when a version of NetBeans less than 7.1 opens a 7.1 project. The solution is;

- Open the file nbproject/build-impl.xml
- remove the rebase attribute and value from the line the error is coming from which is a <copylibs/> tag
 

Tuesday 21 February 2012

Installing .msi files with wine

In a terminal enter;

wine msiexec /i your_file.msi

This will open the file as an exe allowing you to install/run the application.

To reboot wine enter;

wineboot

Linux execution/boot levels

This is the first process that is run by the Linux kernel and is what loads the rest of the system.

There are a number of different execution/boot levels i.e. the mode the computer operates.

The default init is set by a variable called initdefault found in /etc/inittab.

The execution levels are;

0: Halt (i.e. shut down)
1: Single user - reduced set of services, used if others do not boot
2: All services excluding network
3: Full user (no GUI)
4: Not used
5: Full user (with GUI)
6: Reboot

To change the init level enter init [mode] (e.g. init 3). To change the init on startup, change the initdefault value in the inittab file.

To check which level you are on use the who -r command.

For more commands use man init.