- The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
- 1 Answer 1
- Apache Tomcat Native Library
- Headlines
- Building
- Requirements
- UNIX
- Windows
- Install and tests
- Configuring Tomcat
- UNIX
- Windows
- Apache Tomcat 8
- Apache Portable Runtime (APR) based Native library for Tomcat
- Table of Contents
- Introduction
- Installation
- Windows
- Linux
- APR Components
- APR Lifecycle Listener Configuration
- APR Connectors Configuration
- HTTP/HTTPS
- AJP
The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/luowensheng/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
I searched SO, find a similar post: What does «The APR based Apache Tomcat Native library was not found» mean? My software environment is:
The warning you see in the log has no relation to your 404 problem. You will have to provide more details, ideally the Minimal, Complete, and Verifiable example.
1 Answer 1
This error is caused due to many problems for example:
> $cataline_home/webapps/your-project| > -->html,css,images, etc. > -->WEB-INF| > -->classes (your java files) > -->lib (your libraries)
- Make sure java is install on your machine. You can check it by running simply javac on command prompt or using java -version
- You are typing wrong URL address or incomplete URL or URL without tomcat port
- Also make sure you added your classes properly in web.xml file
installing Tomcat APR in MAC is HERE and for Linux following is tested by myself
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
Prerequisites for installing APR APR library APR-util library OpenSSL library
yum install openssl-devel yum groupinstall "Development Tools" mkdir tomcat-apr cd tomcat-apr wget http://www.us.apache.org/dist//apr/apr-1.5.2.tar.gz tar -zxvf apr-1.5.2.tar.gz cd apr-1.5.2 ./configure make make install
The default installation path is /usr/local/apr
Download and Install APR-util wget http://www.eu.apache.org/dist//apr/apr-util-1.5.4.tar.gz tar -zxvf apr-util-1.5.4.tar.gz cd apr-util-1.5.4 ./configure --with-apr=/usr/local/apr make make install
The default path of installation is /usr/local/apr/lib Install JNI Wrapper for APR used by Tomcat (libtcnative)
cd $CATALINA_HOME/bin tar -zxvf tomcat-native.tar.gz cd tomcat-native-1.1.29-src/jni/native ./configure --with-apr=/usr/local/apr --with-java-home=/var/java/jdk1.7.0_45 make make install
The native libraries were installed in /usr/local/apr/lib Integrate APR with Tomcat There are two ways to set Tomcat integrate with APR.
One is you can add the following parameter when start up the Tomcat in bin/catalina.sh: CATALINA_OPTS=»-Djava.library.path=/usr/local/apr/lib»
The other is to add a new environment variable LD_LIBRARY_PATH in /etc/profile:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
After restarting the Tomcat service, we can get the following message in catalina.out log if APR was installed successfully.
Oct 07, 2015 8:08:54 AM org.apache.catalina.core.AprLifecycleListener init INFO: Loaded APR based Apache Tomcat Native library 1.1.29 using APR version 1.5.2. Oct 07, 2015 8:08:54 AM org.apache.catalina.core.AprLifecycleListener init INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Apache Tomcat Native Library
The Apache Tomcat Native Library is an optional component for use with Apache Tomcat that allows Tomcat to use OpenSSL as a replacement for JSSE to support TLS connections.
Headlines
- 2 June 2023 — TC-Native-2.0.4 released The Apache Tomcat team is proud to announce the immediate availability of Tomcat Native 2.0.4 Stable. The sources and the binaries for selected platforms are available from the Download page. Please see the Changelog for a full list of changes.
Building
Requirements
Build tc-native requires three components to be installed:
In debian based Linux those dependencies could be installed by something like:
apt-get install libapr1.0-dev libssl-dev
In rpm based Linux those dependencies could be installed by something like:
yum install apr-devel openssl-devel
UNIX
On all the POSIX systems (Linux, Solaris, HP-UX, AIX etc. ) a well-known configure and make is used to build tc-native.
In the jni/native runs:
to read the description of all the parameters.
./configure --with-apr=$HOME/APR \ --with-java-home=$JAVA_HOME \ --with-ssl=$HOME/OPENSSL \ --prefix=$CATALINA_HOME
to create the includes and makefiles to be able to build tc-native.
Where:
$HOME/APR is something like /usr/bin/apr-1-config or the path where apr is installed.
$JAVA_HOME is something like /home/jfclere/JAVA/jdk11 or the path to a JDK installation. Any JDK should work but it is advisable to use the same JVM version the JVM you use with Tomcat.
$HOME/OPENSSL is the path where OpenSSL is installed.
$CATALINA_HOME is the path where the produced libraries will be installed. Something like $HOME/apache-tomcat-10.1.0
The configure is able to guess most of OpenSSL standard installations. So most of the time the following will be enough:
./configure --with-apr=/usr/bin/apr-1-config \ --with-java-home=/home/jfclere/JAVA/jdk11 \ --with-ssl=yes \ --prefix=$CATALINA_HOME
To build the libraries and install them:
The libraries will be found in $CATALINA_HOME/lib
Windows
Download the Windows sources of tc-native and extract them.
Obtain the Windows sources for APR and OpenSSL. Apply the patches from native/srclib and build APR and OpenSSL for your platform (X86 or X64).
nmake -f NMAKEMakefile WITH_APR=. WITH_OPENSSL=. APR_DECLARE_STATIC=1
More detailed instructions including the steps to create a standard release distribution are provided on the Wiki.
Install and tests
Configuring Tomcat
Apache Tomcat comes with the AprLifecycleListener enabled by default. Still, you should check your conf/server.xml to ensure that something like the following is present, and uncommented:
Please see the Apache Tomcat documentation for configuration specifics.
UNIX
Edit $CATALINA_HOME/bin/setenv.sh (creating the file if necessary) and add the path to the tc-native libraries to LD_LIBRARY_PATH. Something like:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib export LD_LIBRARY_PATH
Start tomcat and check for the messages like these ones:
15-Jun-2022 11:06:23.274 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [2.0.0-dev] using APR version [1.7.0] 15-Jun-2022 11:06:23.298 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 3.0.4-dev 3 May 2022]
Refer to the tomcat documentation to configure the connectors (See Tomcat 10.1.x, Tomcat 9.0.x and Tomcat 8.5.x)
Windows
Edit $CATALINA_BASE\bin\setenv.bat (creating the file if necessary) and add the path to the tc-native libraries, apr and OpenSSL to PATH. For example:
set PATH=%PATH;C:\cygwin\home\support\tomcat-native-current-win32-src\jni\native\Debug;C:\cygwin\home\support\tomcat-native-current-win32-src\jni\apr\Debug;C:\OpenSSL\lib\VC
Start tomcat and check for the messages like these ones:
15-Jun-2022 11:06:23.274 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [2.0.0-dev] using APR version [1.7.0] 15-Jun-2022 11:06:23.298 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 3.0.4-dev 3 May 2022]
Apache Tomcat 8
Apache Portable Runtime (APR) based Native library for Tomcat
Table of Contents
Introduction
Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies. The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as sendfile, epoll and OpenSSL), OS level functionality (random number generation, system status, etc), and native process handling (shared memory, NT pipes and Unix sockets).
These features allows making Tomcat a general purpose webserver, will enable much better integration with other native web technologies, and overall make Java much more viable as a full fledged webserver platform rather than simply a backend focused technology.
Installation
APR support requires three main native components to be installed:
- APR library
- JNI wrappers for APR used by Tomcat (libtcnative)
- OpenSSL libraries
Windows
Windows binaries are provided for tcnative-1, which is a statically compiled .dll which includes OpenSSL and APR. It can be downloaded from here as 32bit or AMD x86-64 binaries. In security conscious production environments, it is recommended to use separate shared dlls for OpenSSL, APR, and libtcnative-1, and update them as needed according to security bulletins. Windows OpenSSL binaries are linked from the Official OpenSSL website (see related/binaries).
Linux
Most Linux distributions will ship packages for APR and OpenSSL. The JNI wrapper (libtcnative) will then have to be compiled. It depends on APR, OpenSSL, and the Java headers.
- APR 1.2+ development headers (libapr1-dev package)
- OpenSSL 1.0.2+ development headers (libssl-dev package)
- JNI headers from Java compatible JDK 1.4+
- GNU development environment (gcc, make)
The wrapper library sources are located in the Tomcat binary bundle, in the bin/tomcat-native.tar.gz archive. Once the build environment is installed and the source archive is extracted, the wrapper library can be compiled using (from the folder containing the configure script):
./configure && make && make install
APR Components
Once the libraries are properly installed and available to Java (if loading fails, the library path will be displayed), the Tomcat connectors will automatically use APR. Configuration of the connectors is similar to the regular connectors, but have a few extra attributes which are used to configure APR components. Note that the defaults should be well tuned for most use cases, and additional tweaking shouldn’t be required.
When APR is enabled, the following features are also enabled in Tomcat:
- Secure session ID generation by default on all platforms (platforms other than Linux required random number generation using a configured entropy)
- OS level statistics on memory usage and CPU usage by the Tomcat process are displayed by the status servlet
APR Lifecycle Listener Configuration
APR Connectors Configuration
HTTP/HTTPS
For HTTP configuration, see the HTTP connector configuration documentation.
For HTTPS configuration, see the HTTPS connector configuration documentation.
An example SSL Connector declaration is:
/conf/localhost.crt" SSLCertificateKeyFile="$/conf/localhost.key" />
AJP
For AJP configuration, see the AJP connector configuration documentation.