Wednesday, February 13, 2008

java: How to deploy EJB in WebSphere using Ant


<property name="package.lib.dir" value="${lib.dir}/package" />

<target name="create-was-ejb">
<property name="ejbdeploy.classpath.prop" refid="ejbdeploy.classpath" />

<path id="ejbdeploy.classpath">
<fileset dir="${package.lib.dir}" includes="*.jar" />
<pathelement location="${was.home}/java/jre/lib/ibmorb.jar" />
</path>

<taskdef
name="wsejbdeploy"
classname="com.ibm.websphere.ant.tasks.WsEjbDeploy"
classpath="${was.home}/lib/wsanttasks.jar" />

<wsejbdeploy
inputJar="${build.dir}/${ant.project.name}-${version}-tmp.jar"
wasHome="${was.home}"
workingDirectory="${build.dir}/ejb-tmp"
classpath="${ejbdeploy.classpath.prop}"
outputJar="${build.dir}/${ant.project.name}-${version}.jar"
compatible35="false"
keepGenerated="true"
quiet="true"
failonerror="true" />
</target>

Monday, February 04, 2008

linux: Linux directory structure

Below is a typical linux directory structure of interest to me :

/etc - contains the configuration files for the system. /etc/rc.d contains the scripts that get the system started.

/bin - has the essential programs that the system requires to operate.

/usr/bin - contains applications for the system's users.

/sbin, /usr/sbin - contain programs for system administration, mostly for use by the superuser.

/usr/local - used for the installation of software and other files for use on the local machine. What this really means is that software that is not part of the official distribution. When you find interesting programs to install on your system, they should be installed in one of the /usr/local directories. Most often, the directory of choice is /usr/local/bin.

/tmp - is a directory in which programs can write their temporary files.



Source: http://www.linuxcommand.org/lts0040.php

Sunday, February 03, 2008

java: A simple ANT template


<?xml version="1.0" ?>
<project name="secondbuildJAR" default="compile">

<property file="${user.home}/build.properties"/>

<property name="source.dir" location="src"/>
<property name="build.dir" location="build"/>
<property name="build.classes.dir" location="${build.dir}/classes"/>
<property name="distribution.dir" location="dist"/>
<property name="distribution.doc.dir" location="${distribution.dir}/doc" />


<property name="project.name" value="${ant.project.name}" />
<property name="project.version" value="0.1.alpha" />
<property name="target.name" value="${project.name}-${project.version}.jar" />
<property name="target.jar" location="${distribution.dir}/${target.name}" />


<patternset id="meta.files">
<include name="**/*.xml"/>
<include name="**/*.properties"/>
</patternset>


<path id="compile.classpath">
<fileset dir="lib">
<include name="*.jar"/>
<include name="*.zip"/>
</fileset>
</path>



<path id="run.classpath">
<path refid="compile.classpath"/>
<pathelement location="${target.jar}"/>
</path>



<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${distribution.dir}" /> <!--this will delete both dist and dist/doc -->

<mkdir dir="${build.classes.dir}" />
<mkdir dir="${distribution.doc.dir}" />
</target>



<!-- Copy metadata to build classpath -->
<target name="copymetafiles" depends="clean">
<copy todir="${build.classes.dir}">
<fileset dir="${source.dir}">
<patternset refid="meta.files"/>
</fileset>
</copy>
</target>



<target name="compile" depends="copymetafiles" description="Compiles the project">
<javac srcdir="${source.dir}"
destdir="${build.classes.dir}"
debug="${build.debug}">
<classpath refid="compile.classpath"/>
</javac>
</target>


<target name="archive" depends="compile" description="JARs up the project">
<jar destfile="${target.jar}"
duplicate="preserve"
manifest="${source.dir}/META-INF/MANIFEST.MF">
<fileset dir="${build.classes.dir}"/>
</jar>
</target>



<target name="execute" depends="archive" description="Executes the main class">
<echo>running this program now!!!</echo>
<java classname="org.antbook.welcome.Main" classpathref="run.classpath" failonerror="true">
<arg value="a" />
<arg value="b" />
<arg file="." />
</java>
<echo>end running the program!!!</echo>
</target>


<target name="echo">
<echo message="ant.file = ${ant.file}" /><!--where this ant file is located-->
<echo message="ant.home = ${ant.home}" />
<echo>ant.version = ${ant.version}</echo>
<echo>java.home = ${java.home}</echo>
<echo message="ant.java.version = ${ant.java.version}" />
<echo>ant.project.name = ${ant.project.name}</echo>
<echo>user.name = ${user.name}</echo>
<echo>user.home = ${user.home}</echo>
<echo>basedir = ${basedir}</echo>
<echo>build.debug = ${build.debug}</echo>
</target>



</project>

Sunday, January 06, 2008

linux: bootloader file location

I have an ASUS F3SV laptop. It's dual boot Vista / Ubuntu. In the boot menu, if I choose the first Vista menu option, the boot loader will be corrupted, making me unable to start up Ubuntu and Vista.

I have no problems getting if into Vista if I choose the 2nd Vista menu option. So, to prevent me from choosing the first Vista option in the first place, I simply commented that option in

/boot/grub/menu.lst

java/linux: Setup ClassPath in Unix/Linux (ubuntu) on your .bashrc

If you want to be able to call eclipse / ant / java from any prompt in your linux system, then
edit your .bashrc and add this lines :

# User specific environment and startup programs
export ECLIPSE_HOME=/usr/local/eclipse
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export ANT_HOME=/usr/share/ant

PATH=$PATH:$ECLIPSE_HOME:$JAVA_HOME/bin:$ANT_HOME/bin

export PATH


note: $PATH is how your current path is configured. If you type in echo $PATH in the command line, you should see something like this
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:

The colon ":" is simply just the delimiter.

Once you've edited your .bashrc, reboot your pc (or type ctrl + alt + backspace) for your new settings to take effect. After you've rebooted, type the following from the command line and see the results :

echo $JAVA_HOME


See :

http://java.sun.com/docs/books/tutorial/essential/environment/paths.html

linux: Add RealPlayer in your Ubuntu

wget -c http://www.debian-multimedia.org/pool/main/r/realplay/realplayer_10.0.9-0.1_i386.deb
sudo dpkg -i realplayer_10.0.9-0.1_i386.deb

See :
http://www.howtoforge.com/the_perfect_desktop_ubuntu_gutsy_gibbon_p6

eclipse: Installing JBoss Tools (formerly known asn JBoss IDE or Hibernate Tools) and SpringIDE via Update Manager

Hibernate tools can be obtained from JBoss tools. To add JBoss tools in eclipse, add this as a "Remote Site" in your Eclipse Update Manager
http://download.jboss.org/jbosside/updates/stable
http://download.jboss.org/jbosstools/updates/stable

For more info, see :
http://docs.jboss.com/jbosside/install/build/en/html/installation.html
http://labs.jboss.com/tools/download/index.html

SpringIDE - just add this to your download manager
http://springide.org/updatesite

Monday, December 17, 2007

sql: querying date column

select * from TABLE_NAME
where
COLUMN_NAME > TO_DATE('2007-12-07 23:59:05','yyyy-mm-dd HH24:mi:SS')

Thursday, October 25, 2007

java: Short regular expression tutorial

^ = logical not

\w = shortcut for alphanumeric. i.e. a-z, A-Z, 0-9, _

- = dash

. = full stop

space bar pressed here = space bar

[\\w-. ] = regular expression for valid characters.

[^\\w-. ] = regular expression for not valid characters (i.e.invalid characters).


//find a character that is not valid (ie. invalid characters are a-z, A-Z, 0-9, _, dash, full stop, and space bar

String regex = "[^\\w-. ]";

---------------------------------------------------------

Below are the common symbols you will often find:

^ The beginning of the line.

$ The end of the line.

. Any single character.

* Zero or more repetitions of the previous expression.

+ One or more repetitions of the previous expression.

[] Any of the characters inside the brackets will match—e.g., [abc] matches any of a, b, c. Ranges are allowed too—e.g., [a-z].

Monday, October 02, 2006

linux: creating symbolic link for java

Symbolic link (aka symlink or shortcut in windoze)

ln -s /usr/java/jdk1.5.0_09/bin/java /usr/local/bin/java
ln -s /usr/java/jdk1.5.0_09/bin/javac /usr/local/bin/javac
ln -s /usr/java/jdk1.5.0_09/bin/javadoc /usr/local/bin/javadoc

linux: How to find where a program is located

To find where firefox is installed, type:
which firefox

To find where java is installed, type:
which java

java/linux: Installing JDK/JavaSE

From command prompt, su as root.

create dir /usr/java
place jdk-1_5_0_09-linux-i586.bin in /usr/java

chmod 777 jdk-1_5_0_09-linux-i586.bi

From /usr/java type
./jdk-1_5_0_09-linux-i586.bin

JDK is now installed in /usr/java/jdk1.5.0_09

linux: How to uninstall a (non-rpm) program

User brute force uninstall :
rm -rf /thedirwhereyourprogramresides

Sunday, January 22, 2006

java: Generating unique sequence of numbers

Calendar calendar = Calendar.getInstance(TimeZone.getDefault());

//generate a unique sequential number. We derive this from the
//number of
milliseconds since 00:00:00 GMT Jan. 1, 1970 using //calendar object.
String runNumber = new Long(calendar.getTime().getTime()).toString();

System.out.println(runNumber);

java: Sorting Dates in a List (Collection)

final String DATE_FORMAT = "dd/MM/yy";
DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
dateFormat.setTimeZone(TimeZone.getDefault());

//we store date as time in milliseconds.
//getTime() returns the number of milliseconds since
//midnight of January 1, 1970. This method is also very
//useful for generating a unique sequence of numbers.
Long date0 = new Long(dateFormat.parse("29/01/1995").getTime());
Long date1 = new Long(dateFormat.parse("13/12/2007").getTime());
Long date2 = new Long(dateFormat.parse("01/04/2000").getTime());

List dateList = new ArrayList();
dateList.add(date0);
dateList.add(date1);
dateList.add(date2);

Collections.sort(dateList);

//Get wrapper Long from list. convert Long to String. 
//Convert String to primitive long. Convert primitive long to Date.
Date dateLatest = new Date(Long.parseLong(((Long) dateList.get(dateList.size()-1)).toString()));
String dateLatestString = dateFormat.format(dateLatest);

System.out.println(dateLatestString);

javascript: Sorting Date in an Array (Collection)



function getDateLatest()
{
var date0 = new Date('12/31/2005');
var date1 = new Date('11/29/2007');
var date2 = new Date('01/13/1999');

var dateArray = new Array();

//we store date as time in milliseconds.
//getTime() returns the number of milliseconds since
//midnight of January 1, 1970. This method is also very
//useful for generating a unique sequence of numbers.
dateArray[0] = date0.getTime();
dateArray[1] = date1.getTime();
dateArray[2] = date2.getTime();
dateArray.sort(sortNumber);

var dateLatest = new Date(dateArray[dateArray.length - 1]);
alert(dateLatest);}

//By default, Array sorts alphabetically. To get it to sort
//numerically, we write a function that compares numbers.
function sortNumber(a, b)
{
return a - b
}