1

I have imported two library in my project

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

now I want to use class HttpServletRequest from package javaee-web-api. Problem is that javax servlet contains this class too and application is using this instead of library what I want to. How I can change it ?

hudi
  • 15,555
  • 47
  • 142
  • 246
  • 2
    Couldn't you just use the jee api and remove the servlet api? I think jee already contains the full servlet api. – Stephan Aug 13 '12 at 07:12
  • Care to explain why you *can not do this*? – maba Aug 13 '12 at 07:17
  • because dependency javax.servlet I have in parent project which I cant edit and now I am creating new where I need to use javaee-web-api – hudi Aug 13 '12 at 07:21

3 Answers3

2

You cannot. Remove either one. Both classes are in the same namespace/package. HttpServletRequest is defined by a standard it should behave the same way.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
1

Since you have a comment now that explains that the javax.servlet is coming from the parent pom then I don't think it is possible. It has been discussed before: Is there anyway to exclude artifacts inherited from a parent POM?

If you have any kind of control on the parent pom then you should try to change it to have an optional tag:

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

Then it won't be included as a transitive dependency for your child project.

http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

Community
  • 1
  • 1
maba
  • 47,113
  • 10
  • 108
  • 118
1

Ok I found it. I can exclude this library:

<exclusions>
                <exclusion>
                    <artifactId>servlet-api</artifactId>
                    <groupId>javax.servlet</groupId>
                </exclusion>
            </exclusions>

and then it works

hudi
  • 15,555
  • 47
  • 142
  • 246