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

前端 未结 5 1251
孤城傲影
孤城傲影 2020-12-16 20:06

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

5条回答
  •  北海茫月
    2020-12-16 20:15

    Here is a code snippet you can put into your main method in Java to output paths to all dependencies of your application:

    ClassLoader cl = ClassLoader.getSystemClassLoader();
    URL[] urls = ((URLClassLoader) cl).getURLs();
    for(URL url: urls){
        System.out.println(url.getPath());
    }
    

提交回复
热议问题