Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list of Java class dependencies for a main class?

Is there a way to find all the class dependencies of a java main class?

I have been manually sifting through the imports of the main class and it's imports but then realized that, because one does not have to import classes that are in the same package, I was putting together an incomplete list.

I need something that will find dependencies recursively (perhaps to a defined depth).

like image 628
Ron Tuffin Avatar asked Oct 14 '08 09:10

Ron Tuffin


People also ask

What does Jdeps do?

The jdeps command shows the package-level or class-level dependencies of Java class files. The input class can be a path name to a . class file, a directory, a JAR file, or it can be a fully qualified class name to analyze all class files.

How do I find runtime dependencies?

You can use tools jdeps for check dependencies in classpath (if before JDK 9), but it can not help you check all source code, only apply with standalone Java class. Since JDK 9, you can use modular, with keyword requires inside file module-info. java of module.

What does @inject do in Java?

Injectable constructors are annotated with @Inject and accept zero or more dependencies as arguments. @Inject can apply to at most one constructor per class. @Inject is optional for public, no-argument constructors when no other constructors are present. This enables injectors to invoke default constructors.


1 Answers

You may want to take a look at the jdeps command line tool:

https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html

jdeps -cp <your cp> -v <path to your .class file>

The command will return a list of the dependencies for that java class file. There are many other options that you can use in your command like -regex to find dependencies matching a given pattern

like image 133
Daniel Alencar Avatar answered Nov 15 '22 19:11

Daniel Alencar