Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup Tomcat libraries dependencies in maven POM

I am currently migrating our build process from Eclipse/Ant to Maven/M2Eclipse/Artifactory. I have a Webapp as a WTP project in Eclipse. I have migrated it to Maven with m2eclipse.

The compilation runs fine from the Eclipse IDE.

However, when I try to compile from Maven CLI (mvn clean & mvn compile), Maven complains about not finding the libraries provided by the Tomcat Environment (like annotations-api, servlet-api, etc, ...).

Fair enough : Indeed, these dependencies are provided by WTP, as Java resources / Libraries / ApacheTomcat6. Maven is not aware of them.

I could deactivate this in the build path, and add each corresponding dependency in my POM, but I'm afraid this would lead Maven to deploy them again in my webapp (WEB-INF/libs).

So, what is the good way to say to maven "this application will run in a well known environment, providing the following libraries ". Is there some common Tomcat POM that I could add as a dependency ?

Thanks in advance for your advice. regards,

Raphael

like image 426
Raphael Jolivet Avatar asked Jan 14 '11 10:01

Raphael Jolivet


1 Answers

One way to handle this is to declare these dependencies with scope provided. These dependencies will be available for compile and test, but will not be packaged by maven into the webapp. For example,

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
like image 80
Raghuram Avatar answered Sep 21 '22 23:09

Raghuram