Jar Hell for Unit testing with jboss projects

I an trying to set up some unit tests using ESIntegTestCase. It seems that RandomizedRunner uses jboss servlet jars. This is causing jar hell for me. Where is this dependency? I need to exclude it.

java.lang.RuntimeException: found jar hell in test classpath
at org.elasticsearch.bootstrap.BootstrapForTesting.(BootstrapForTesting.java:90)
at org.elasticsearch.test.ESTestCase.(ESTestCase.java:168)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:592)
Caused by: java.lang.IllegalStateException: jar hell!
class: javax.servlet.annotation.WebFilter
jar1: /xx/.m2/repository/org/jboss/spec/javax/servlet/jboss-servlet-api_3.0_spec/1.0.1.Final/jboss-servlet-api_3.0_spec-1.0.1.Final.jar
jar2: /xx/.m2/repository/org/jboss/spec/javax/servlet/jboss-servlet-api_3.1_spec/1.0.0.Final/jboss-servlet-api_3.1_spec-1.0.0.Final.jar
at org.elasticsearch.bootstrap.JarHell.checkClass(JarHell.java:277)
at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:187)
at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:88)
at org.elasticsearch.bootstrap.BootstrapForTesting.(BootstrapForTesting.java:88)

Are you sure those libs are coming from randomized testing framework ?

Good point. I'm not sure. But I don't know how to find out. The Eclipse dependency tree does not show up the jar.

May be share your pom.xml if it makes any sense.
But I'm sure there are other eclipse users here who might have ideas...

I narrowed the problem down to a dependency on another project. Am including the pom for that project.

	<!-- Spec APIs provided by JBoss AS -->
	<dependency>
		<groupId>org.jboss.spec.javax.annotation</groupId>
		<artifactId>jboss-annotations-api_1.1_spec</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.jboss.spec.javax.resource</groupId>
		<artifactId>jboss-connector-api_1.7_spec</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.jboss.spec.javax.ejb</groupId>
		<artifactId>jboss-ejb-api_3.2_spec</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>javax.enterprise</groupId>
		<artifactId>cdi-api</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>javax.mail</groupId>
		<artifactId>mail</artifactId>
		<scope>provided</scope>
	</dependency>
	
	<!-- JBoss AS components -->
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-core</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-envers</artifactId>
		<scope>provided</scope>
	</dependency>
	
	<!-- 3rd party libraries -->
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-core</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-annotations</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-databind</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
        <groupId>org.apache.cxf</groupId>
		<artifactId>cxf-rt-frontend-simple</artifactId>
		<scope>provided</scope>
	</dependency>
	<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <scope>provided</scope>
	</dependency>
	<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-core</artifactId>
        <scope>provided</scope>
	</dependency>
	<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <scope>provided</scope>
        <exclusions>
        	<exclusion>
        		<groupId>org.opensaml</groupId>
        		<artifactId>opensaml</artifactId>
        	</exclusion>
        </exclusions>
	</dependency>
	<dependency>
        <groupId>org.apache.ws.security</groupId>
        <artifactId>wss4j</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.ws</groupId>
        <artifactId>jbossws-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
	    <groupId>org.elasticsearch.client</groupId>
	    <artifactId>transport</artifactId>
        <scope>provided</scope>
        <exclusions>
        	<exclusion>
        		<groupId>com.fasterxml.jackson.core</groupId>
        		<artifactId>jackson-core</artifactId>
        	</exclusion>
        	<exclusion>
        		<groupId>com.fasterxml.jackson.core</groupId>
        		<artifactId>jackson-annotations</artifactId>
        	</exclusion>
        	<exclusion>
        		<groupId>com.fasterxml.jackson.dataformat</groupId>
        		<artifactId>jackson-dataformat-smile</artifactId>
        	</exclusion>
        	<exclusion>
        		<groupId>com.fasterxml.jackson.dataformat</groupId>
        		<artifactId>jackson-dataformat-yaml</artifactId>
        	</exclusion>
        	<exclusion>
        		<groupId>com.fasterxml.jackson.dataformat</groupId>
        		<artifactId>jackson-dataformat-cbor</artifactId>
        	</exclusion>
        </exclusions>
	</dependency>
	
	
	
	
	
	<!-- testing -->
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.hamcrest</groupId>
		<artifactId>hamcrest-all</artifactId>
		<scope>test</scope>
	</dependency>
	
	<dependency>
		<groupId>javax.xml.rpc</groupId>
		<artifactId>javax.xml.rpc-api</artifactId>
		<version>1.1.1</version>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.jboss.spec.javax.el</groupId>
		<artifactId>jboss-el-api_3.0_spec</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.apache.neethi</groupId>
		<artifactId>neethi</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>

<build>
	<finalName>${project.artifactId}</finalName>

	<plugins>
		<plugin>
			<artifactId>maven-antrun-plugin</artifactId>
			<executions>
				<execution>
					<id>gis-build-properties</id>
					<phase>prepare-package</phase>
					<configuration>
						<target>
							<hostinfo prefix="buildhost" />
							
							<mkdir dir="${project.build.outputDirectory}/META-INF" />
							
								<propertyset>
									<propertyref prefix="java." />
								</propertyset>
								<propertyset>
									<propertyref prefix="os." />
								</propertyset>
							</echoproperties>

						</target>
					</configuration>
					<goals>
						<goal>run</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
		<plugin>
			<artifactId>maven-ejb-plugin</artifactId>
			<configuration>
				<!-- Tell Maven we are using EJB 3.1 -->
				<ejbVersion>3.1</ejbVersion>
			</configuration>
		</plugin>
		<plugin>
			<artifactId>maven-shade-plugin</artifactId>
			<executions>
				<execution>
					<phase>package</phase>
					<goals>
						<goal>shade</goal>
					</goals>
					<configuration>
						<shadedArtifactAttached>true</shadedArtifactAttached>
						<shadedClassifierName>merged</shadedClassifierName>
						<artifactSet>
							<includes>
								<!-- matching resources will be overwritten in the order of processing 
									defined by the include list below (impacts META-INF/*.xml files) -->
								
							</includes>
						</artifactSet>
					</configuration>
				</execution>
			</executions>
		</plugin>

		<!-- Attach test-jar -->
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-jar-plugin</artifactId>
			<executions>
				<execution>
					<id>default-test-jar</id>
					<phase>package</phase>
					<goals>
						<goal>test-jar</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

So you probably exclude some conflicting libs in your own pom I believe.

Good luck :slight_smile:

Is there a way to find where a jar is being called from? I have tried maven-duplicate-finder and tattletale, and they both don't work for me. Any other way to locate errant jars?

You are misunderstanding the stack trace. You have JAR hell with two of your own dependencies, versions 3.0 and 3.1 of the servlet spec. These are not coming from randomized runner but they are simply on the stack trace since randomized runner is our test runner and we have JAR hell checks in our base test class.

How do I locate which dependancies are pointing to these jars? I have tried

  • Various exclusions in my pom
  • Viewing the classpath in Eclipse (this shows only one of the jars being loaded)
  • mvn dependency:tree -Dverbose=true (does not show these jars)

What else can I do?

It seems that jar hell that ESIntegTestCase is something a lot of users run into, so it would be good to figure out a solution to this.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.