2

I'm running a Websphere 7 project. Pom structure is the following:

my project

<parent>
    <groupId>company</groupId>
    <artifactId>websphere-superpom</artifactId>
    <version>version</version>
</parent>
<dependencies>
    ...
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>2.2.5</version>
    </dependency>
</dependencies>
...

websphere-superpom

<dependencies>
    ...
    <dependency>
        <groupId>com.ibm.websphere</groupId>
        <artifactId>runtime-dependencies</artifactId>
        <version>version</version>
        <type>pom</type>
        <scope>provided</scope>
    </dependency>
</dependencies>

runtime-dependencies

<dependencies>
    ...
    <dependency>
        <groupId>com.ibm.websphere</groupId>
        <artifactId>j2ee</artifactId>
        <version>version</version>
    </dependency>
</dependencies>

Artifact j2ee contains several packages, among them there is also javax.el and it is loaded before the one I declare in my project's pom.

I run a JUnit test with the option -verbose:class and the output confirmed this problem.

[Loaded javax.el.ExpressionFactory from file:/C:/Program Files (x86)/IBM/SDP/runtimes/base_v7/lib/j2ee.jar]

I then run the following command in Maven console:

mvn dependency:analyze -DcheckDuplicateClasses

and the output I got is this:

[WARNING] Unused declared dependencies found:
...
[WARNING]    javax.el:javax.el-api:jar:2.2.5:compile
...

How to tell Maven to load ExpressionFactory from the library I declared in my project's pom? I cannot change websphere-superpom because it's a company managed artifact.

EDIT: As asked by watery I tried to redeclare the offending dependency in my project's pom as following:

<dependency>
    <groupId>com.ibm.websphere</groupId>
    <artifactId>runtime-dependencies</artifactId>
    <version>version</version>
    <exclusions>
        <exclusion>
            <groupId>com.ibm.websphere</groupId>
            <artifactId>j2ee</artifactId>
        </exclusion>
    </exclusions>
</dependency>

But then Maven tells me:

Could not resolve dependencies for project ....: Failure to find com.ibm.websphere:runtime-dependencies:jar in nexus url
Andrea
  • 336
  • 2
  • 9
  • 32
  • Yes. I need the newer version because Hibernate Validator 5.1.2.Final needs javax.el-api version 2 minimum, and the one included in j2ee.jar is older. Sadly it's always loaded the one in j2ee.jar first so I get java.lang.NoSuchMethodError: javax.el.ExpressionFactory.newInstance – Andrea Aug 29 '14 at 08:13
  • Have a look at [this question](http://stackoverflow.com/q/2681759/3127111) (I didn't read it all) – watery Aug 29 '14 at 10:48

1 Answers1

0

If it is possible for you to modify parent dependencies, you could make use of maven exclusions.

In websphere-superpom:

<dependency>
    <groupId>com.ibm.websphere</groupId>
    <artifactId>runtime-dependencies</artifactId>
    <version>version</version>
    <type>pom</type>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
          <groupId>javax.el</groupId>
          <artifactId>javax.el-api</artifactId>
        </exclusion>
    </exclusions> 
</dependency>

EDIT:
If you use watery's suggestion, don't forget to set the scope of this runtime-dependencies as provided. Because now Maven tries to search it in your nexus repo.

mkrakhin
  • 3,386
  • 1
  • 21
  • 34
  • Sadly I can't modify websphere-superpom, because it's a company managed artifact. I tried excluding j2ee from my project pom, but it says "Missing artifact com.ibm.websphere: runtime-dependencies:jar"(weird!) – Andrea Aug 29 '14 at 08:00
  • @Andrea I don't know if this will work: try to re-declare, in *your* POM that same dependency as your super POM, and then specify there the exclusion. – watery Aug 29 '14 at 08:17
  • Updated my question with your suggestion – Andrea Aug 29 '14 at 08:23
  • Even after setting the scope as provided it does not find runtime-dependencies... – Andrea Aug 29 '14 at 09:53