我尝试在带有来自我的Web服务器的jar的applet中使用AspectJ加载时编织,因为我在库上使用Java反射调用。必须加载的类的名称作为参数传递。因此,我无法使用编译时编织 这是我的小程序“MyApplet”的一些代码:
URLClassLoader appletClassLoader = (URLClassLoader)
RemoteConfigurationApplet.class.getClassLoader();
URL[] urlList = appletClassLoader.getURLs();
URL aspectJar = null;
try {
aspectJar = new URL("https://myserver:8443/MyWebApp/applet/MyApplet.jar/");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
WeavingURLClassLoader weavingClassLoader = new WeavingURLClassLoader(urlList,
new URL[]{ aspectJar }, Thread.currentThread().getContextClassLoader());
然而,我总是得到一个例外:
org.aspectj.bridge.AbortException: bad aspect library: "/MyWebApp/applet/MyApplet.jar"
我怀疑在“addAspectLibrary”中使用文件对象来解决问题:
private void addAspectLibrary(String aspectLibraryName) {
File aspectLibrary = new File(aspectLibraryName);
if (aspectLibrary.isDirectory() || (FileUtil.isZipFile(aspectLibrary))) {
try {
info("adding aspect library: '" + aspectLibrary + "'");
weaver.addLibraryJarFile(aspectLibrary);
} catch (IOException ex) {
error("exception adding aspect library: '" + ex + "'");
}
} else {
error("bad aspect library: '" + aspectLibrary + "'");
}
}
它会删除URL,然后在硬盘上查找无法找到它的文件。 有人有解决方案让它运行吗?