Defining a JNDI DB connection with Tomcat

1. Install Your JDBC Driver

Copy the driver’s JAR file(s) into the $CATALINA_HOME/lib directory, which makes the driver available both to the resource factory and to your application.

2. Bootstrap the project

If you don’t have a project to play with already, you can bootstrap a project with Spring Roo. I’ve used version 1.2.1. I . . . → Read More: Defining a JNDI DB connection with Tomcat

Creating a WebApp project with Maven

With the archetype maven-archetype-webapp is possible to generate a simple webapps with Maven:

$ mvn archetype:generate \ -DgroupId=org.obliquid \ -DartifactId=tomcat-test \ -DarchetypeArtifactId=maven-archetype-webapp \ -Dversion=1.0-SNAPSHOT $ mvn package $ mvn tomcat:run

This starts an embedded Tomcat server and it will be browsable at http://localhost:8080/tomcat-test/

To have more detail of a Maven plugin, use the help plugin, . . . → Read More: Creating a WebApp project with Maven

How to format a Joda Time date with JSTL

To format a JDK Date with JSTL, first I import the taglib

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"/>

and then use the formatDate tag with a pattern.

<fmt:formatDate value="${aDoc.issueDate}" pattern="MMM dd yyyy"/>

However this approach doesn’t work with Joda Time, when I tried I got the following error:

javax.el.ELException: Cannot convert 2011-05-01T00:00:00.000+08:00 \ of type class org.joda.time.DateTime . . . → Read More: How to format a Joda Time date with JSTL

Mod-jk on Ubuntu 10.10

I’ve already installed mod-jk on Linux and Windows, but this time I’m going to install it on Ubuntu 10.10. I’ve already Installed Apache 2.2 (2.2.16 in mpm-prefork flavor in this case because of PHP) and libapache-mod-jk 1.2.28-2 using Ubuntu packages and Apache Tomcat 7.0.11 from the official Tomcat distribution rather than a Ubuntu package.

The . . . → Read More: Mod-jk on Ubuntu 10.10

Tomcat org.apache.commons.httpclient.HttpConnection.open NullPointerException

After deploying a MVC web application on Tomcat that worked in my eclipse development environment, I had this NullPointerException when trying my application online.

java.lang.NullPointerException org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:720) org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1321) org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386) org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170) org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396) org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324) com.amazonaws.http.HttpClient.execute(HttpClient.java:193)

This is Tomcat security manager in action, not allowing Socket connections to the web application. The message is somewhat misleading, so I thought . . . → Read More: Tomcat org.apache.commons.httpclient.HttpConnection.open NullPointerException

Mod_Jk with Wamp (Apache 2.2.11)

Previously I blogged about installing Mod_jk with Tomcat 5.5 on Linux. This time I’m going to install Mod_jk aka Tomcat Connector on Windows. The binary version can be downloaded here:

http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/

I downloaded mod_jk-1.2.28-httpd-2.2.3.so – renamed to mod_jk.so and copied to

C:\wamp\bin\apache\Apache2.2.11\modules

I create C:\wamp\bin\apache\Apache2.2.11\conf\workers.properties with the following content

# Define 1 real worker using . . . → Read More: Mod_Jk with Wamp (Apache 2.2.11)

Netbeans 6.5 – Error starting wsgen

Here is how I have lost a lot of time for a stupid error.I could not compile any more my webservice project because of the following error.

wsgen-init: wsgen-KinesService: C:\Users\stefano\Documents\NetBeansProjects\kines_api\nbproject\jaxws-build.xml:18: Error starting wsgen: BUILD FAILED (total time: 6 seconds)

According to this article only jaxb-api.jar and jaxws-api.jar have to be copied, but this approach didn’t . . . → Read More: Netbeans 6.5 – Error starting wsgen

mod_jk with Tomcat 5.5

One year ago I was moving my first steps with Java webservices and today with Java annotations the task to write a webservice is easier.

I’ve already talked about installing mod_jk but it was with Java 1.4 and Tomcat 4.1. Today I’m trying with Java 1.6 and Tomcat 5.5 with apache 1.3.

From http://www.apache.org/dist/tomcat/tomcat-connectors/jk/source/ I . . . → Read More: mod_jk with Tomcat 5.5

Enabling a Tomcat Manager Login on Tomcat 5.5

To enable Tomcat Manager/Admin Login on Tomcat 5.5 edit conf/tomcat-users.xml which by default has the following content:

<?xml version=’1.0′ encoding=’utf-8′?> <tomcat-users> <role rolename=”tomcat”/> <role rolename=”role1″/> <user username=”tomcat” password=”tomcat” roles=”tomcat”/> <user username=”both” password=”tomcat” roles=”tomcat,role1″/> <user username=”role1″ password=”tomcat” roles=”role1″/> </tomcat-users>

Change it into:

<?xml version=’1.0′ encoding=’utf-8′?> <tomcat-users> <role rolename=”manager”/> <role rolename=”admin”/> <user username=”admin” password=”your_password_here” roles=”manager,admin”/> </tomcat-users>

. . . → Read More: Enabling a Tomcat Manager Login on Tomcat 5.5

Installing Tomcat 5.5 on Linux

Installing Tomcat 5.5 on Linux is rather simple. Tomcat 5.5 requires a JDK version 1.5 or above. I previously installed a JDK 1.6 SE downloaded jdk-6-linux-i586.bin from http://java.sun.com/ and I’ve installed it into /usr/local/jdk1.6.0

STEP 1: Adding user tomcat

# useradd -m -d /home/tomcat tomcat

Note: useradd and groupadd are the POSIX standardized tools to . . . → Read More: Installing Tomcat 5.5 on Linux