How to Build the latest mod_jk RPM

mod_jk is an Apache module used to connect the Tomcat servlet container with web servers such as Apache. It has come increasingly difficult to find a an apache2-mod_jk-1.2.37-4.1.src.rpm or apache2-mod_jk-1.2.37-4.1.rpm as some of the links are now dead.  However, after tracking down a copy of the apache2-mod_jk-1.2.37-4.1.src.rpm, a modification or two to the .spec file along with the official .tar.gz file will allow for a successful build of a mod_jk RPM for use on CentOS 6 with Apache 2.2.

Using rpmrebuild, it was plain that the official build used this source, apache2-mod_jk-1.2.37-4.1.src.rpm.

Download Dependancies

#yum install -y rpm-build rpmdevtools pcre-devel openssl-devel zlib-devel redhat-rpm-config gcc gcc-c++ make libstdc++-devel wget rpmlint vim httpd-devel libtool
yum install -y httpd-devel gcc gcc-c++ make libtool
rpmdev-setuptree

Create your build environment

rpmdev-setuptree
cd ~/rpmbuild/SOURCES/

Download and Build

# Download the source RPM
wget ftp://ftp.pbone.net/vol2/ftp5.gwdg.de/pub/opensuse/repositories/home%3A/adesso/SLE_11_SP2/src/apache2-mod_jk-1.2.37-4.1.src.rpm
# Extract to ~/rpmbuild/SOURCES/
rpm2cpio apache2-mod_jk-1.2.37-4.1.src.rpm | cpio --extract --make-directories --verbose

# Copy the apache2-mod_jk.spec file to correct location
cp ~/rpmbuild/SOURCES/apache2-mod_jk.spec~/rpmbuild/SPECS/apache2-mod_jk.spec

Modify the .spec file
Removing IF statements for SUSE Linux and a couple of dependencies which didn’t seem to be needed.

#
# spec file for package apache2-mod_jk (Version 1.2.30)
#
# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

# norootforbuild

Name:           apache2-mod_jk
#BuildRequires:  httpd >= 2.2 httpd-devel >= 2.2 pcre-devel java-1.6.0-openjdk-devel gcc-c++ ruby-libs
BuildRequires:  httpd >= 2.2 httpd-devel >= 2.2 pcre-devel gcc-c++

%define section        free
%define       connectors_root           tomcat-connectors-%{version}-src
%define       apache2_sysconfdir        %(/usr/sbin/apxs -q SYSCONFDIR)
%define       apache2_libexecdir        %(/usr/sbin/apxs -q LIBEXECDIR)
%define       apache2_cflags            %(/usr/sbin/apxs -q CFLAGS)
Summary:        Connectors between Apache and Tomcat Servlet Container
Version:        1.2.41
Release:        1.0
License:        Apache Software License ..
Group:          Productivity/Networking/Web/Frontends
Requires:       httpd >= 2.2
Provides:       mod_jk = %{version}-%{release}
Provides:       mod_jk-ap20
Provides:       mod_jk-ap20:%{_libdir}/httpd/modules/mod_jk.so
Obsoletes:      mod_jk-ap20 < %{version}
Obsoletes:      tomcat-mod  < %{version}
Url:            http://jakarta.apache.org
#Source0:        http://www.apache.org/dist/tomcat/tomcat-connectors/jk/source/jk-%{version}/tomcat-connectors-%{version}-src.tar.gz
Source0:        https://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-%{version}-src.tar.gz
Source1:        jk.conf
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
This package provides modules for Apache to invisibly integrate Tomcat
capabilities into an existing Apache installation.

To load the module into Apache, run the command "a2enmod jk" as root.

Authors:
--------
Hans Bergsten <hans@gefionsoftware.com>
James Duncan <Davidson duncan@x180.com>
Pierpaolo Fumagalli <pier@apache.org>
Craig McClanahan <cmcclanahan@mytownnet.com>
Sam Ruby <rubys@us.ibm.com>
Jon Stevens <jon@clearink.com>
Anil Vijendran <akv@eng.sun.com>
Brian Behlendorf <brian@behlendorf.com>
Kevin Burton <burton@relativity.yi.org>
Danno Ferrin <shemnon@earthlink.net>
Jason Hunter <jh@servlets.com>
Ramesh Mandava <rmandava@talentportal.com>
Stefano Mazzocchi <stefano@apache.org>
Rajiv Mordani <mode@chinet.com>
Harish Prabhandham <harishp@onebox.com>
Jean-Luc Rochat <shachor@il.ibm.com>
James Todd <jwtodd@pacbell.net>

%prep
%setup -q -n %{connectors_root}

%build
# prepare apr
export APACHE2_CFLAGS="%{apache2_cflags}"
cd $RPM_BUILD_DIR/%{connectors_root}/native
./configure --with-apxs=/usr/sbin/apxs
make

%install
# AJP Connector jk
install -d -m 755 $RPM_BUILD_ROOT%{apache2_libexecdir}
pushd $RPM_BUILD_DIR/%{connectors_root}
install -m 755 native/apache-2.0/.libs/mod_jk.so $RPM_BUILD_ROOT%{apache2_libexecdir}/
popd
cp %{SOURCE1} .

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%doc LICENSE
#mod_jk.conf.sample workers.properties.sample
%doc conf/workers.properties
%doc jk.conf
%{apache2_libexecdir}/*

%changelog
* Mon Apr 18 2016 Canon <canon@it.megocollector.com> - 1.2.41-1.0
- Build from source

* Thu Aug 18 2011 stoppe@gmx.de
- Initial release

Download the source

spectool -R -g ~/rpmbuild/SPECS/apache2-mod_jk.spec

Bump the build and comment it.

rpmdev-bumpspec --comment="Build from source" --userstring="Canon <canon@it.megocollector.com>" ~/rpmbuild/SPECS/apache2-mod_jk.spec

Optional: check the .spec

rpmlint ~/rpmbuild/SPECS/apache2-mod_jk.spec

Build it

rpmbuild -ba ~/rpmbuild/SPECS/apache2-mod_jk.spec

Check out your Build

rpmbuild -qlp /root/rpmbuild/RPMS/x86_64/apache2-mod_jk-1.2.41-1.0.x86_64.rpm

Install it

yum install apache2-mod_jk-1.2.41-1.0.x86_64.rpm