Posts Tagged ‘Web’

Ant build script for java web project with tomcat on ubuntu

December 7th, 2013

Here is a sample ant build script for java web project with tomcat on ubuntu. It should be put under the root directory of the web project.

<?xml version="1.0" encoding="UTF-8"?>
<project name="ProjectName" default="war" basedir=".">
	<property environment="env" />
	<property name="" value="ProjectName" />
	<property name="webapp.dir" value="/data/public/JavaWebapps" />
	<property name="tomcat.lib" value="/usr/share/tomcat7/lib" />
	<property name="ant.lib" value="/usr/share/ant/lib" />
	<property name="dist.dir" value="${basedir}/war" />
	<property name="webRoot.dir" value="${basedir}/WebContent" />
	<property name="src.dir" value="${basedir}/src" />
	<property name="config.dir" value="${basedir}/resources" />
	<property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" />
	<property name="build.dir" value="${basedir}/build" />
	<!-- Init classpath -->
	<path id="project.classpath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		<fileset dir="${tomcat.lib}">
			<include name="*.jar" />
		<!-- ant lib  -->
		<fileset dir="${ant.lib}">
			<include name="*.jar" />

	<!-- get the source compile classpath in a printable form -->
	<pathconvert pathsep="${line.separator}|   |-- "
	<!-- show classpath jars -->
	<target name="print_classpath">
		<echo message="|-- compile classpath"/>
		<echo message="|   |"/>
		<echo message="|   |-- ${echo.path.compile}"/>
	<target name="clear" description="Clear the project">
		<delete dir="${build.dir}" />
		<delete dir="${dist.dir}" />
		<delete file="${}/${}.war" />
		<delete dir="${}/${}" />

	<target name="init" depends="clear" description="Init the directories">
		<mkdir dir="${build.dir}/classes" />
		<mkdir dir="${dist.dir}" />

	<target name="compile" depends="init" description="Compile source files">
		<echo message="begin compile..." />
		<javac srcdir="${src.dir}" destdir="${build.dir}/classes" 
			includeantruntime="false" nowarn="on" 
			target="1.7" deprecation="true" debug="true" 
			encoding="UTF-8" classpathref="project.classpath" 
			<compilerarg line="-Xlint:unchecked" />
			<!-- <classpath refid="project.classpath" /> -->
		<copy todir="${build.dir}">
			<fileset dir="${src.dir}">
				<include name="**/*.xml" />
				<include name="**/*.properties" />
				<include name="**/*.sql" />
			<fileset dir="${config.dir}">
				<include name="**/*.xml" />
				<include name="**/*.properties" />
				<include name="**/*.sql" />
		<echo message="end compile..." />

	    <target name="pack" depends="compile"> 
	        <jar jarfile="${build.dir}/${}.jar"> 
	            <fileset dir="${build.dir}/classes"> 
	                <include name="**/*.class"/> 

	<target name="war" depends="compile" description="Package the project as .war file.">
		<echo message="begin packing war..." />
		<war destfile="${dist.dir}/${}.war" basedir="${webRoot.dir}" 
			<lib dir="${lib.dir}" />
			<classes dir="${build.dir}/classes" />
			<fileset dir="${webRoot.dir}">
				<include name="***.*" />
		<echo message="end war..." />

	<target name="deploy" depends="war" description="Deploy the war to tomcat">
		<echo message="begin deploy..." />
		<copy file="${dist.dir}/${}.war" todir="${webapp.dir}" />
		<echo message="end deploy..." />


Memo of using analog to measure website traffic

July 6th, 2012

A sudden heavy load was detected on our server. On this server the only public service is https which serves a few websites. I check the auth logs and didn’t find anything abnormal. So I wonder it’s some sudden heavy requests were thrown on the apache server. I have never used any web log analyzer before, and googled a little and found analog should do the job for me. Here is just a memo of what I did today.

Install the analog package

On a debian/ubuntu server, one can easily install analog by:
#> (sudo) apt-get install analog
On windows, one can simply download the latest binary package, extract it, and then use it.

Basics of analog

Analog is a program that is used to analyze the apache logs and show the statics that may interest you.

To use analog, you need to provide it a config file, telling it where the logs are, and where to output the results, and what things should be in the results. The default config file in debian (if you install it by “apt-get”) will be /etc/analog.cfg. You can edit the file and then run analog without any parameter. Here is an example:

# tell analog where the log file is
LOGFILE /var/log/apache2/access.log
# tell analog where and the format to output the result
OUTFILE /home/me/host.stat.html
# the name of the host. this will be part of the title of the report.
# the link of the host.
# analog use some simple images to show the bars or to make the report more friendly. If you installed analog by "apt-get", there are under "/usr/share/analog/images/"; if you installed analog by download the binary package, the images directory is under the extracted root directory.
IMAGEDIR "/usr/share/analog/images/"

How to use a different config file and how to analyse more than one website

see this great article HOW-TO Use Analog for Virtual Hosts (Using Separate Logfiles)

How to show different sections or columns

analog can show the report by hourly, daily, monthly or yearly. Each can be a section in the report. And in each section, you can choose what things to show. Refer to & to see the things you can show.

One can find the detail document here: