【发布时间】:2015-04-23 19:01:19
【问题描述】:
我只是想尝试一下 javassist,然后开始编辑库的方法体。要连接到库,我使用位于 '%JAVA_HOME%..\lib\' 中的 tools.jar 附加了一个代理。
但我不喜欢我使用的每台电脑都只为 tools.jar 安装 jdk 的想法
难道没有其他方法可以将 jar 的输入提取到我的最终 jar 中吗?
我用 javassist 这样做了,它似乎工作正常(IntelliJ 这样做了。它有一个很好的功能http://puu.sh/hoiCo/bf19853b12.png)
但是使用 tools.jar 会导致程序抛出异常
异常http://puu.sh/hoiGd/844567bca2.png的截图
public static void main(String[] args){
if(args.length < 1){
log("No ProcessID set");
return;
}
String pid = args[0];
VirtualMachine vm = null;
try{
vm = VirtualMachine.attach(pid);
String filePath = AgentMain.class.getProtectionDomain().getCodeSource().getLocation().getPath();
filePath = URLDecoder.decode(filePath, "UTF-8");
if(filePath.startsWith("/")){
filePath = filePath.substring(1);
}
log("Loading Agent... [" + filePath + "]");
vm.loadAgent(filePath);
}catch(Exception ex){
log("VM connection error [" + pid + "]");
ex.printStackTrace();
}finally{
try{
if(vm != null) vm.detach();
}catch(Exception ex){}
}
}
这是我用于注入代理的代码。
如果有人可以提供帮助,那就太好了。
我希望你明白:)
【问题讨论】:
标签: java intellij-idea javassist tools.jar