Basil Bourque
Basil Bourque

Reputation: 338181

Specify Apache Tomcat "lib" folder in Maven

In Apache Tomcat 9, the JNDI Resources How-To page has a section at the bottom, Adding Custom Resource Factories.

To write a class that implements the JNDI service provider javax.naming.spi.ObjectFactory interface, the doc says:

You will need to compile this class against a class path that includes all of the JAR files in the $CATALINA_HOME/lib directory.

That lib folder contains:

websocket-api.jar
tomcat-jni.jar
tomcat-util-scan.jar
tomcat-util.jar
tomcat-websocket.jar
tomcat-i18n-pt-BR.jar
tomcat-i18n-ru.jar
tomcat-i18n-zh-CN.jar
tomcat-jdbc.jar
tomcat-i18n-ja.jar
tomcat-i18n-ko.jar
tomcat-i18n-cs.jar
tomcat-i18n-de.jar
tomcat-i18n-es.jar
tomcat-i18n-fr.jar
jaspic-api.jar
jsp-api.jar
servlet-api.jar
tomcat-api.jar
tomcat-coyote.jar
tomcat-dbcp.jar
el-api.jar
jasper-el.jar
jasper.jar
catalina-tribes.jar
catalina.jar
ecj-4.12.jar
catalina-ha.jar
catalina-storeconfig.jar
annotations-api.jar
catalina-ant.jar

➥ How do I satisfy this requirement in a Maven-driven project?

I certainly do not want all those jars bundled into the resulting WAR file of my web app.

Upvotes: 0

Views: 940

Answers (1)

stdunbar
stdunbar

Reputation: 17435

It's a bit unclear from the docs what is really needed but, in general, you will have something like the following in your pom.xml:

<dependency>
    <groupId>jndi</groupId>
    <artifactId>jndi</artifactId>
    <version>1.2.1</version>
    <scope>provided</scope>
</dependency>

The key is the provided scope. This means that the library is needed for compilation but should not be included as part of the packaging. In other words, it is provided by the destination deployment environment.

Having said that, the link you provide is for writing a custom resource factory. It will not be a .war file but will instead be a .jar that you would install into Tomcat to extend it. Is that what you're after? If you just need to do a JNDI lookup then the chunk of XML I provided will work for your code.

Upvotes: 1

Related Questions