7

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

1 Answer 1

11

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>
4
  • 1
    Above is the way you need to define in your pom. change the scope to provided so maven does not include those jars in your final build.
    – fmucar
    Commented Jan 14, 2011 at 13:40
  • 2
    Thanks,Do you know if Tomcat provides a POM project with all libraries already listed as "provided" ? I could then add it as a dependency. Commented Jan 17, 2011 at 17:11
  • @RaphaelJolivet that would be neat, also looking for this (but for Glassfish, actually). Did you find anything? Commented Jan 4, 2012 at 14:31
  • Is it possible to have m2eclipse (or mvn eclipse:eclispe) add the dependencies to the generated project/classpath ?
    – herman
    Commented Aug 23, 2012 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.