Finding duplicate classes in your WAR files with Tattletale
Join the DZone community and get the full member experience.
Join For FreeHave you ever found all sorts of weird errors when running your webapp because several jar files included have the same classes in different versions and the wrong one is being picked up by the application server?
Using JBoss Tattletale tool and its Tattletale Maven plugin you can easily find out if you have duplicated classes in your WAR WEB-INF/lib folder and most importantly fail the build automatically if that’s the case before it’s too late and you get bitten in production.
Just add the following plugin configuration to your WAR pom build/plugins section. It can also be used for EAR, assemblies and other types of projects.
<plugin> <groupId>org.jboss.tattletale</groupId> <artifactId>tattletale-maven</artifactId> <version>1.1.0.Final</version> <executions> <execution> <phase>verify</phase> <!-- needs to run after WAR package has been built --> <goals> <goal>report</goal> </goals> </execution> </executions> <configuration> <source>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</source> <destination>${project.reporting.outputDirectory}/tattletale</destination> <reports> <report>jar</report> <report>multiplejars</report> </reports> <profiles> <profile>java6</profile> </profiles> <failOnWarn>true</failOnWarn> <!-- excluding some jars, if jar name contains any of these strings it won't be analyzed --> <excludes> <exclude>persistence-api-</exclude> <exclude>xmldsig-</exclude> </excludes> </configuration> </plugin>
You will need to add the JBoss Maven repository to your POM repositories section, or to your repository manager. Make sure you use the repository that only contains JBoss artifacts or you may experience conflicts between artifacts in that repo and the Maven Central repo.
Adding extra repositories is a common source of problems and makes builds longer (all repos are queried for artifacts). What I do is add an Apache Archiva proxy connector with a whitelist entry for org/jboss/** so the repo is only queried for org.jboss.* groupIds.
<repository> <id>jboss</id> <url>https://repository.jboss.org/nexus/content/repositories/releases</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository>
Source: http://blog.carlossanchez.eu/2011/03/23/finding-duplicate-classes-in-your-war-files-with-tattletale/
Opinions expressed by DZone contributors are their own.
Comments