blong824
blong824

Reputation: 4030

Adding Tomcat Library to Maven

I am taking my first crack at Maven and ran into a problem. We have an application that is deployed on Tomcat 6. We have several jar files added to the lib folder of tomcat. Then in our build path we add this tomcat library.

How can I add the tomcat library to maven? Is this a bad way to do this? Are there any alternatives?

Thanks in advance

Upvotes: 2

Views: 11329

Answers (3)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298818

Anything in tomcat's lib directory should be a maven dependency with scope provided:

provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

Source: Maven Dependency Scope

Example:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

If the libraries are your own, you will have to install or deploy them to a local or remote repository.

Upvotes: 9

matt b
matt b

Reputation: 139921

You should list each of the dependencies of the project in the <dependencies> section of your POM.

This way Maven knows to compile against them, and to include these dependencies in the WEB-INF/lib folder of the .war file it packages for you. IDEs that support Maven can then include these libraries in the classpath they use to display/build/run your code as well.

Upvotes: 1

Joseph Ottinger
Joseph Ottinger

Reputation: 4951

You should add the dependencies to the maven project, apart from the Tomcat installation. Then, set their scope to "provided" so that they're not bundled with the artifact.

Upvotes: 1

Related Questions