Monday, April 25, 2011

Setting up Apache2 and Tomcat6 on Ubuntu 10.04

This is a short post on setting up Apache2 and Tomcat6

Install Java
apt-get -y install python-software-properties
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
apt-get update
apt-get install -y sun-java6-jdk

Install tomcat6 with apache2 support
apt-get -y install tomcat6 libtcnative-1 libapache2-mod-jk

Setup worker.properties with the following values:
workers.tomcat_home=/usr/share/tomcat6
workers.java_home=/usr/lib/jvm/java-6-sun
nano /etc/libapache2-mod-jk/workers.properties

Modify /etc/apache2/mods-available/jk.load
cat >>/etc/apache2/mods-available/jk.load <<EOF
JkWorkersFile /etc/libapache2-mod-jk/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel error
EOF

Setup virtual host
cat >/etc/apache2/sites-available/test.henyo.com <<EOF
NameVirtualHost *
<VirtualHost *>
        ServerName test.henyo.com
        JkMount /* ajp13_worker
</VirtualHost>
EOF

Activate the site
a2ensite test.henyo.com

Setup tomcat for ajp13
nano /etc/tomcat6/server.xml

Restart tomcat and apache2
service tomcat6 restart
service apache2 restart

Install and configure UFW
apt-get install ufw
ufw allow ssh
ufw allow http
ufw enable

Install and configure Tripwire
apt-get install tripwire

I hope you found the post useful. You can subscribe via email or subscribe via a feed reader to get relevant updates from this blog. Have a nice day.

Sunday, April 17, 2011

Setting up a Spring Data JPA Project

This post is about setting up a Maven Project based on Spring Data JPA. I spent a few hours today nailing it down. Hopefully it saves someone some time to bring a project up quickly.

- Spring Framework based application
- makes use of Spring Data JPA for easy Repositories
- makes use of JPA 2.0 persistence with EcliplseLink
- JUnit4 and spring-test
- Logging using SL4J to Log4J

For the impatient, I uploaded a sample project on github: spring-data-jpa-trial

You can also download the tar ball or zip file from these links.

I started with a blank Maven Project created with STS 2.5.2.SR1 created using
the New Maven Project wizard checking the Create a simple project(skip archetype selection).

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>test</description>
</project>

Added some entries to the pom file to setup 1.6
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

Setup spring-data-jpa dependency
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.0.0.M2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<repository>
<id>spring-milestone</id>
<name>Spring Maven MILESTONE Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>

Setup persistence dependecies
<!-- Persistence dependencies -->
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring.framework.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.2.0</version>
<scope>runtime</scope>
</dependency>
<repository>
<id>EclipseLink Repo</id>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo</url>
</repository>

Setup logging dependencies as discussed in the Spring Framework Reference Docs
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${sl4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${sl4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${sl4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>runtime</scope>
</dependency>

Setup Testing Dependencies
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.framework.version}</version>
<scope>test</scope>
</dependency>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>        
<argLine>-javaagent:spring-instrument-3.0.5.RELEASE.jar</argLine>
</configuration>
</plugin>

I hope you found the post useful. You can subscribe via email or subscribe via a feed reader to get relevant updates from this blog. Have a nice day.