Find jars containing class file in Maven project
As far as I know, there is no dedicated Maven plugin (3.0+) that will look for dependencies for class declarations. However, I believe I understand your needs and suggest the following solutions:
Find duplicate ads
mvn dependency:analyze-duplicate -DcheckDuplicateClasses
Find containing JAR in Eclipse
Use CTRL+ SHIFT+ Tto bring up the Open Type dialog . Entering part or full name of a class is a list of containing JAR files in the assembly classpath.
Find containing JAR without IDE
If you need more programmatic control to check on systems without an IDE, such as a CI server, you can use the following snippets to view JAR files that contain a specific class or even a specific name pattern. This approach uses the Maven Dependency Plugin to collect all dependencies in a temporary directory so that they can be easily found.
For Unix systems or Git Bash
mvn clean dependency:copy-dependencies -DoutputDirectory=target/temp
for j in target/temp/*.jar; do jar -tf $j | grep SomeClass && echo $j; done
For Windows through the shell cmd
mvn clean dependency:copy-dependencies -DoutputDirectory=target/temp
for /R %G in (target\temp\*.jar) do @jar -tf "%G" | find "SomeClass" && echo %G
In either case, the corresponding complete package entry and class name will be displayed, followed by the name of the JAR file containing. The search parameters grep
and find
can be further refined to restrict matches as needed, for example SomeClass.class
.
Hope this helps.
source to share