IntelliJ - 如何获取模块的类路径

时间:2017-07-13 02:57:54

标签: intellij-idea

我是IntelliJ的新手并且正在开发一个包含数百个模块的大项目,我只是想知道如何获得特定模块的类路径?

1 个答案:

答案 0 :(得分:0)

它可能对你有所帮助。因为每个模块都有自己独立的类路径。您可以组合项目中所有模块的类路径,以及该方法的功能,但尝试使用该类路径不太可能在多模块项目中产生正确的行为。

public static String getFullClassPath(Module m){
String cp = "";
cp += CompilerPaths.getModuleOutputPath(m,false);

for(VirtualFile vf : OrderEnumerator.orderEntries(m).recursively().getClassesRoots()){
    String entry = new File(vf.getPath()).getAbsolutePath();
    if(entry.endsWith("!/")){ //not sure why it happens in the returned paths
        entry = entry.substring(0,entry.length()-2);
    }
    if(entry.endsWith("!")){
        entry = entry.substring(0,entry.length()-1);
    }
    cp += File.pathSeparator + entry;
}
return cp;

}

相关问题