Archive for the ‘Development’ Category

LogDigger Mantis Setup

If you are a frequent web application coder you will no doubt have done endless hours of testing and bug fixing. What this tutorial will hopefully provide you with is a quick and easy way, to setup, and maintain a live Mantis issue tracking system, with an added bonus of utilising the issue reporting application LogDigger. What are they I hear you say, and why use them together. At this point I could ramble on about the two programs but as there sites already do this here are the links:

now you can as you have probably seen on the LogDigger site use LogDigger witha number of issue tracking applications. I have chosen Mantis because its quick and easy to set-up an environment to use it in.

Setting up the environment

Firstly we are going to have to setup a PHP MySQL environment in order for Mantis to work, if you have this already great skip this section if not we can get you up and running really quickly with the very useful package that is WAMP Server LAMP if your on Linux but as I don’t personally use Linux all that much, this tutorial will be based around WAMP.

WAMP

WAMP stands for Windows, Apache, MySQL, PHP. and it all comes bundled for you in a handy .exe, so all we need do now is go to the following link and download WAMP.

Once Installed on your machine (and if you have chosen C:\ as the install location) you will find a directory called wamp within that there is a directory called www this is where we need to place Mantis. To check if WAMP is working you will see in the bottom right of your screen the following icon wamp working. If like in this image its all white your cooking on gas if not check that you have disabled IIS in your services. When you have disabled IIS restart all services associated with WAMP by clicking the following.

wamprestart

Mantis

So now you should have a fully working WAMP server. if you go to the following Link we can get Mantis downloaded.

with the Mantis zip downloaded. Take that file and unzip it to the following location C:\wamp\www. and rename the directory to mantisbt

now in a your browser of choice navigate to http://localhost/mantisbt you should be presented with the setup page of mantis asking you for multiple settings passwords and usernames i leave to you. but the most important part of this page is the database. If we refer to the image above you will see that there is a link listed called phpMyAdmin. we need to go there now.

phpMyAdmin

Within phpMyAdmin we need to create a new database for Mantis to utilise. This is done by writing the name of the database in the box provided phpMyAminCreateand clicking create. rememember the name and enter this in the Mantis setup page. Run the setup page when all aettings are to your desires. when setup is complete you should have all the fields shown as green.

mantisgreen

We should all now have mantis installed and be able to login. (defauly password is usually administrator and the password is usually root).

follow the simple instructions to create a project within the manage section. This will save time once we have installed LogDigger.

Tomcat

Now this is where some die hards will be telling me i have it wrong and I should be implemement a Tomcat with PHP MySQL integrated, and yes I agree but for this quick setup guide to demonstrate the benefits of these systems I am going to use the quick and easy way two seperate installs.

Get the latest Tomcat from here

I would reccommend the windows installer as this will be relatively painless.  Install this now if you installed in C:\tomcat you will be able to find your webapps directory here C:\tomcat\webapps this directory will be the one that you will be installing LogDigger upon.

LogDigger

We need to get the .war version of LogDigger this will be the quickest and most painless way to install LogDigger find it at the following link

tomcat will automatically unpack the .war file and install it as a web application, the one point I will make would be that the .war file should be renamed in order for the app to have a sensible name, for example I simply removed the version number to leave logdigger.war. Once renamed place the .war file into the webapps directory and let Tomcat work its magic.

now we have logDigger installed we need to set it up and test that it is accessible, to do this try the following. If you have left Tomcat on the default port of 8080 then you can navigate to the following url in your browser of choice. http://localhost:8080/logdigger/ this should bring up logdiggersetupthe LogDigger setup page. follow the 6 easy steps and we are nearly there.

All you need to do now is define a project within LogDigger and if you have done everything up to this point correctly you will see that LogDigger takes all it’s projects from your Mantis installation. Once setup we need to start issue tracking, to do this we need to install the LogDigger browser extension.

Browser Extension

At the time I wrote this there were only two extensions available they are for Internet Explorerand Firefox.

if you go to the link below and download the relevant extension

once installed you should be able to report issues on the fly while

JSP Navigation using Directories

This is not particularly hard or something you will want to do with every site you ever develop. That being said i recently used this same technique to list and make links of all of my web apps within a Tomcat configuration I have. First things first you will need to be running a platform capable of parsing JSP files for this to work and it is always a good idea to have your Java up to date currently I’m running 1.6.

The Scenario

We are developing an application that will check, and report back which applications are installed upon our Tomcat install. Further more we are ( having made sure that each web application has, in there root directory either an index or default page) going to create links to those pages.

ROOT

I am using the ROOT directory within the webapps directory, for the base of my application. I have emptied this directory and in its place put an empty index.jsp file.

at the top of the file is the usual language declaration,

<%@ page language=”java” contentType=”text/html; charset=UTF-8″
pageEncoding=”UTF-8″%>

below this we are going to place an empty function that we will write later, this function  will deal with the creation of the links.

<%!

public String createLink(String dir){

}

%>

As you can see from the above declaration the method will expect a String and return one also. The string being passed in will be the directory name. The returned will be the link in its fully formed and valid format.

Getting The Directory Contents

To do this we need a file object, a String array and a String.  We place the relative location of the webapps directory within our string. Then call upon and instantiate the Java File object like so.

String filename=”..\\webapps\\”;

java.io.File file = new java.io.File(filename);

This code can be placed just before the last %> of the previous code section. this code takes the java.io.File object and creates  a new instance of itself using the String supplied in this case the location of the webapps directory. We name this new File object file. We now take the contents of that directory and use the list method with the file object itself, to populate the String array.

String [] dirs = file.list();

We now have all the information we need to pass the Strings to the createLink function.

The Loop

To pass the individual strings into the createLink function we will loop through the array like so.

<ul>

<%
for(int i = 0; i < dirs.length; i++){

// if directory we are in skip it
if(dirs[i].equals(“ROOT”)){
continue;
}
String newLink = createLink(dirs[i]);
out.println(newLink);
}
%>

</ul>

You can see that there is a conditional check within the loop. If you remember we jumped out one directory with the file object so in affect we would have created a link to our own app. I chose not to but if you wish to have your own app listed simply remove this if statement block.

So now we need to create the function to create the links, I hope you have noticed that the separation is not totally necessary depending upon what you require you could quite easily fill the loop with this code and list out the directories. I have other purposes and other checks that needed to be done so I decided to put all these in a separate function. The code of which is here:

String link = “”;

link = “<li><a href=\”../” + dir + “\”>” + dir + “</a></li>”;

return link;

This code should be placed within the function block we created at the beginning. and that’s it all done with one reminder. This is very basic and should be used as such there has been very limited testing on this and most of the code was written in not copy and pasted in so please check for syntax errors especially in the ” ” areas.

Deploy Solr on Tomcat

This article will guide you through the process of deploying Apache Solr 1.3 onto a Tomcat environment. To do this we will be utilising Tomcat’s context fragments. We will not be covering how to index using Solr, I would highly recommend looking at Solrj for this.

My Setup

I feel it is important for you to know what platform I am deploying Solr onto. I am running Windows XP, with Tomcat 6.0.20.

Preparation

Before we start lets make sure you have all the right software. I would recommend if like me you are using a windows based system to install Tomcat using the windows installer available from the Tomcat download site once downloaded and installed do not start the service. secondly download the Solr.war file from the Solr download site and keep it somewhere safe on your server/machine and note the path to the war file. Now we are ready to create the context.

The Context

The context fragment needs to be placed in a specific directory structure, firstly navigate to tomcat\conf directory. Once there create a directory whose name is Catalina which will reference your Tomcat installation within that directory create a further directory with the name of your host, for example in my basic example I will be using my machine as the host so the directory will be called localhost.

Within this directory create an XML file called [whatever you want your index to be called].xml this file is the context fragment. For example my context file is called unimaginatively solr.xml.

Coding the Fragment

Within your new empty context fragment we need to add a short burst of code pointing tomcat at a few key places within Solr. firstly we have to tell Tomcat where to get the Solr.war file we downloaded earlier, remember the path, good.

<Context docBase=”..\conf\apache-solr-1.3.0.war” debug=”0″ crossContext=”true” >

The docbase attribute of the context is relatively to your bin directory i.e. for a standard installation the bin directory can be found within the Tomcat directory. So you can see from the first line of this code, that my war file is within the conf directory and I point to it using a relative path from the bin directory.

<Environment name=”solr/home” type=”java.lang.String” value=”../conf/solr” override=”true” />

The next line and believe it or not the last required line of code within the context, is going to tell Tomcat where to place the Solr home this is the configuration files, and data directory for Solr so in essence where your data will be stored. So as you can see from the the code that again I have placed my Solr home within the conf directory of Tomcat. Again this path is relative to the bin directory.

and that’s it you now should have a working Solr deployment.

Hope this helps.

Starting Tomcat

Now we are ready to start the Tomcat service. When the service starts you should notice two directories appear the first will be within the conf directory, and the second will be within webapps directory

Java Recursive directory listings

A simple and yet troublesome for some, part of Java coding, is the ability to move recursively through directory structures. When processing directories full of files this is most definitely needed. We can accomplish this with a simple logic jump. We need to create a method to process all the files of a given directory, that when a directory is encountered calls itself passing in the new File that contains the directory.

The Test Directories

So to start out we need a directory to test with. I created a C:/test directory with example1.txt and example2.txt files. I then created the directory C:/test/exampledir and within that directory example3.txt and example4.txt.

The Main Method
package recurse;public static void main(String[] args){public class Main {// Pass in the test directoryExample.recurse("C:/test");}}

From the code above you can see we are calling a class named Example and within that class a method named recurse, and into that method we are passing a the directory path as a String.

The Example Class

package recurse;

import java.io.File;

public class Example {

public static void recurse(String dir){

}

At the start you can see that I have made this method have a return type of void this is because we are not going to pass back any information. this can easily be changed but is out of the scope of this tutorial. So lets set about collecting and dealing with the Files, firstly we need to store the directory we have just passed in.
// create file object for directory
File directory = new File(dir);

We do this in a File object, we now need to list all the files within that directory, but we need somewhere to store them. Creating a String array here is probably the simplest answer.

// get list of files from directory into a String array
String[] files = directory.list()

now with all the files in that directory contained within the String array we are set. I would like to pause here and make a very important point that may have already occurred to you, but is easily missed. The File object is not only capable of containing files but directories too, this point is very important to remember as we continue.

The Loop

We are at the pivotal point. Now we must loop through the files contained within the String array and determine what we need to do with each file.

// loop through files
for(int i = 0; i < files.length; i++){
// place current file string within a file object
procFile = new File(directory,files[i]);
// use file object to check if current file is a directory
if(procFile.isDirectory()){
// if file is a directory recurse
recurse(procFile.getPath());
}else{
// print out file name
System.out.println("The current file: " + procFile.getPath());
}
}

We can now assign the latest entry to be called by the loop to the procFile File object. then we test to see if procFile is a directory, if it is we call our self passing in procFile which will become the directory at the start of the method, allowing us to drop down and eventually crawl back up the tree directory structure. If however the procFile was not a directory its path is printed out.

Hope this helps let me know if you have any questions.

Return top