gpt4 book ai didi

java - 注解处理时如何获取编译类路径?

转载 作者:太空宇宙 更新时间:2023-11-04 13:38:28 25 4
gpt4 key购买 nike

我的尝试是

ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] currentClassPath = ((URLClassLoader) cl).getURLs();
String[] classPathStrings = Arrays.stream(currentClassPath).map(url -> {
try {
return Paths.get(url.toURI()).toAbsolutePath().toString();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}).toArray(String[]::new);
System.out.println(Arrays.asList(classPathStrings));

在注释处理器的 process() 方法主体中。但它只输出
[C:\Program Files\Maven\boot\plexus-classworlds-2.5.1.jar]

而不是已处理项目的依赖项。

最佳答案

嗯,使用getClass().getClassLoader()就足够了。注释处理器上下文中的 getClass()

关于java - 注解处理时如何获取编译类路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31452728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com