Tuesday, March 3, 2009

Set up a project managed by SVN

Samuel agreed to help me and get into this project, which makes me so happy. For the sake of teaching me conveniently, he set up a project in sourceforge.net, and told me how to use SVN to manage the project. The name of our project is Biological Network COmparison Toolkit(bnct), and weblink is: https://sourceforge.net/projects/bnct/.

Here is how to set up a project locally managed by SVN.

Firstly, download TortoiseSVN and install it. After the installation, it is integrated into the Windows Explorer. Create an empty folder to hold the coming project,for example, D:\Projects\bnct, and enter it.

Secondly, in this folder, right click and select SVN Checkout, then a property window pop out for setting.

Set the URL repository to: https://bnct.svn.sourceforge.net/svnroot/bnct/trunk, leave others default and click OK to make sure. After this, the fold will contain one gray .svn folder and several folder ticked like this:

Fourthly, right click on bnct, tortoiseSVN -> Settings, go to context menu. In the Cascaded context menu, make these options: Checkout.., Update, Commit.. , Diff and Check for modifications... checked then click OK for sure.

Next, go to Diff Viewer in the settings of TortoiseSVN, configure the program used for comparing different revisions of files as the External program. Here we use WinMerge. Set it like this:
After that, click OK.

TortoiseSVN -> Repo-browser, here is the view of the svn repository in sourceforge. You can check the project in sourceforge conveniently.

Thursday, February 19, 2009

How to debug or run a maven project

Here is the steps to add a tag for running or debugging a maven project. Open "Debug Configurations" by right click on the Eclipse. Also you can open this window by "Run" menu.
1. Give your tag a name, for exmaple, "run App";
2. Use "Browse file system " to fill in the Base directory. For my project, it should be "D:\Projects\netcomp\netcomp", the root path for the project.

3. Fill the blank of Goals by "clean package exec:java";

4. Click Configure at the right side of Maven Runtime and add an external address for the Maven running. It should be the path where your maven installed.

After all the steps, the "run App" tag for running a maven project is built up. When you need to do the debugging, enable the debug configurations window and click debug.

The import of netcomp

"netcomp" is the name of my little project.
Yesterday, after Samuel helped me modified it, I try to update the codes by cover the old files by the new ones. However, because Eclipse has some kind of history record for the old java files, after I re-open Eclipse to see the imported new java files, there are a lot of red crosses on the left side of the new packages and methods. Samuel told me to "Clean ..." and then "Update all the Maven projects" in the project menu of Eclipse. Because I didn't do it in the right order, it seemed useless. So I delete all the projects (there are kegg and netcomp previously) and try to import them in by click "import" and "Maven project". But it's wrong.
The right way to import the maven project to eclipse is,

Step 1. Unzip netcomp to D:\Projects. So now the right path for netcomp is D:\Projects\netcomp.

Step 2. run cmd and cd D:\projects\netcomp. Under this path, run : mvn eclipse:clean

Step 3. cd D:\projects\netcomp\netcomp. Under this path, run: mvn eclipse:eclipse.

Step 4. under D:\projects\netcomp, run: mvn clean install.
Up to now, my own .project for maven is generated.
Note: Run mvn eclipse:eclipse in the child netcomp, the one will be imported in the Eclipse as an existing java project later.

Step 5. In Eclipse, "Import" -> "General" -> "Existing Projects into Workspace" -> "Next" -> "Browse" to select the root directory. When you open "D:\Projects\netcomp" by browse, "netcomp" project will appear in the blank for Projects in this window. Then select it and "finish". If Kegg project appears in this blank too, omit it, it's enough only to import netcomp project.
Attention, in this step, it must be "Existing Projects into Workspace" instead of "Maven project" which is imported. It doesn't mean the option "Maven project" is useless, but since we've already built up the project by (cmd -> mvn eclipse:eclipse) , this project is an Existing project insead of an unbuilt Maven project. If you insist to use "import Maven project", then step 3 should be omitted. Or else, this import can be failed.

The installation of Eclipse and M2Eclipse

Before Eclipse, I've tried JBuilder, Together and MyEclipse. All these are the bundle of Java tools, whose core is Eclipse. They are cracked warez. So when I try to install M2Eclipse, the Maven add-on, various problem occurred. Finally I make up my mind to uninstall them all and turn to the simple Eclipse.

As an open source software, Eclipse is no need to be installed. The version I use now is eclipse-java-ganymede-SR1-win32, the economical version. I copy the unzip folder to C:\. So the installation path is C:\Eclipse.

Step 1. Modify Eclipse.ini and change the target of quick link for eclipse.exe.
I don't know why this file have to be modified. But if not, you will get error report when you run Eclipse with Maven together.
Add the following line in front of -vmargs.
"-vm
C:\Java\jdk1.6.0_10\bin\javaw.exe"
Meanwhile, change the properties of the quick link for Eclipse. The new Target should be "C:\Eclipse\eclipse.exe -vm C:\java\jdk1.6.0_10\bin\javaw.exe".

Note: Here is a bug for JVM. If you add "-vm C:\Java\jdk1.6.0_10\bin\javaw" instead of "-vm C:\Java\jdk1.6.0_10\bin\javaw.exe". It will show a "FATAL ERROR" message after the "BUILD SUCCESSFUL" of Maven information when debugging.

Step 2. Install M2Eclipse for Eclipse. (Note: M2Eclipse means "maven version 2 for eclipse")
In Eclipse, click "Help", then "Software Update", then "Avaliable Software",then "Add site". In the blank for "Location", fill in "http://m2eclipse.sonatype.org/update/ ". After that, the List of avialbe software will include "Maven Integaration for Eclipse Update Site". Make sure it's selected, then click "Install" on the right side. When the installation is finished, then this add-on is installed successfully.

Log4j

Log4j, I think, means "log for java". It is an useful tool to show the list of debugging or running log. Log4j has 6 levels, which are FATAL, ERROR, WARN, INFO, DEBUG and TRACE.
There are two ways to configure log4j. One is with a properties file, named log4j.properties, and the other is with an XML file. Within either these 3 components are necessary: Loggers, Appenders and Layouts. Configuring logging via a file has the advantage of turning logging on or off without modifying the application that uses log4j.
Loggers are logical log file names; The actual outputs are done by Appenders. Appenders use Layouts to format log entries.
To debug a misbehaving configuration use the Java VM Property - Dlog4j.debug which will ouput to standard out. To find out where a log4j.properties was loaded from inspect getClass().getResource("/log4j.properties");
Here is An Example Samuel wrote, which is the content of log4j.properties in /Main/Resource.

# The root logger is assigned priority level info and it's appender is stdout
log4j.rootLogger=info, stdout

# stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd/MM/yy HH:mm:ss} %c{1} %p - %m%n

# limit categories
log4j.logger.com.tt.netcomp=INFO

He said actually he diddn't use log4j directedly, but use Commons Logging(JCL) instead, whose backend includes Log4j.
This sentence, "log4j.appender.stdout=org.apache.log4j.ConsoleAppender" is to write log information out to the console; but if we need to write it out to a certein file instead of console, we can use the following sentence:
log4j.appender.stdout=org.apache.log4j.RollingFileAppender
log4j.appender.stdout.File= filepath

For example, it can be something like this:

# ----------------------log4j.properties -----------------------------------------#
# The root logger is assigned priority level infor and it's appender is fileout;
log4j.rootLogger = INFO, fileout

# fileout
log4j.appender.file out=org.apache.log4j.RollingFileAppender
log4j.appender.fileout.File=output.log
log4j.appender.fileout.MaxFileSize=100KB
log4j.appender.fileout.MaxBackupIndex=1
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n

# limit categories
log4j.logger.com.tt.netcomp = INFO

# --------------------Over----------------------------#

In addition, different package can be set to different limit level. For example,

# limit categories
log4j.logger.com.tt.netcomp. domain = DEBUG
log4j.logger.com.tt.netcomp. service = WARN

In this case, domain package will have the limit level as debug while service package as warn. The other package are set to be info as default since we assign the rootLogger level as INFO in the root setting area.

Sunday, February 15, 2009

What's Maven


These days I learnt a lot on Maven and Java, especially how to use it. I need to record them one by one so as not to forget them soon.

First of all, what's Maven. (Maven in five minutes.)

The most useful two commands:
1.
project_path>mvn clean package, to rebuild
2. project_path>mvn clean package exec:java, to clean, rebuild and run it.

Import Maven add-on to MyEclipse. Since the Together and the JBuilder I used before didn't support this add-on, M2Eclipse, because of their old version, I have to change the work tool to MyEclipse.

Step 1.
Afte
r installation of MyEclipse, click Help, then Software Updates, then Find and install, then Search for new features to install. It will open a new window.

New Remote Site... Then Type M2Eclipse in the name area and copy this line: http://m2eclipse.sonatype.org/update/ to URL. Then finish.Select the options of the M2Eclipse tree which would not fail the update(there are three not to enable)
Step 2.
Winkey + R open
the cmd window. Go to the project folder, here is D:\project\netcomp. Execute this command of mvn:
mvn eclipse:eclipse


Step 3:
Go to Eclipse, import the two projects, kegg and netcomp.

Step 4.
Right click the projects one bye one. There is a maven menu, choose "Enable Dependency Management". Now the projects are managed by Maven dependently.








Wednesday, February 11, 2009

NullPointerException

This sentence:
receivers.addAll( lookupMap.get(it.next() ) );

/* --------------------------------------------------------*/
Please input the name of pathway:
aae00010
Connecting to KEGG...
Connected successfully.
java.lang.NullPointerException
at java.util.AbstractCollection.addAll(AbstractCollection.java:303)
at org.tingting.bn.mn.graphbuilder.test.PathGraphBuilder.main(PathGraphBuilder.java:161)
/*---------------------------------------------------------*/

Now I've found why this problem occurred. NPE(NullPointerExcetion) is caused by Null point of the input variable. Here it is because lookupMap.get( ) returns a Null. I disabled the paragraph to generate the lookupMap for the sake of easy debugging, but I don't notice that this lookupMap is used when enzymerelationshipMap is generated.