1

Adding the following snippet to my code:

Message message = PhaseInterceptorChain.getCurrentMessage();
HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
request.getRemoteAddr();

Created a situation in which I had to add the following dependency (cxf.version is defined as 2.7.1):

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>

Although I already had earlier in my pom.xml the following:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
        <type>jar</type>
        <scope>runtime</scope>
    </dependency>

If I don't add that later dependency, the project will not build, complaining "package org.apache.cxf.transport.http does not exist".

If I remove the earlier one (the one with <scope>runtime</scope>), the project will build successfully but the .war will fail to deploy with ClassNotFoundException: org.apache.cxf.endpoint.AbstractEndpointFactory.

Why are 2 occurrences of the same exact groupId/artifactId/version needed in the same pom.xml?

How do I clean/tidy up my pom.xml so that this package is only listed once?

Withheld
  • 4,603
  • 10
  • 45
  • 76
  • 1
    Could you remove first and try change scope to "provided" for the second one? – Eugen Martynov Oct 18 '13 at 15:33
  • @EugenMartynov Thanks. I just tried your suggestion and I am getting `package org.apache.cxf.transport.http does not exist`. So it appears that changing `runtime` to `provided` doesn't help in this case. – Withheld Oct 18 '13 at 15:40

1 Answers1

1

Problem solved. For the benefit of all I am providing the solution.

All I did was to remove that apparent redundancy was to move the earlier one (i.e. with <type>jar</type>) down, replacing the second one and removing the <scope> line. Thus, remaining with only:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
        <type>jar</type>
    </dependency>

But further down the dependencies list.

It appears that the order of dependencies does matter (please correct if you know otherwise).

Withheld
  • 4,603
  • 10
  • 45
  • 76
  • 1
    it does matter - they are ordered in classpath based on pom order. This has been seen in other contexts as well. See [this thread](http://stackoverflow.com/questions/793054/maven-classpath-order-issues), or other sources ([1](http://whyjava.wordpress.com/2010/05/09/maven-classpath-ordering-lesson-learnt/) [2](http://ars-codia.raphaelbauer.com/2014/03/maven-pro-tip-dependency-ordering-and.html) [3](http://java.dzone.com/articles/5-maven-tips)) – eis Aug 19 '14 at 06:58