RE Business服务器通 过基于CORE Business Eclipse RCP客户端来显示已输入的数据报表。设计CORE Business Server过程中,对于重用相同逻辑和客户端已有的诸如Hibernate和Jasper Reports组件的需 求越发明显。显而易见的需求重用的解决方案是将服务器端的Java类重新打包为jar文件,并 将此jar文件包含在WAR文件中。在这个解决方案中,随着Java类结构的改变,原本复杂的构 建脚本也需要不断的修正。实际采用的解决方案非常简单,就是让Tomcat变地对“插件 敏感”。
Eclipse IDE帮助系统使用了Tomcat的内嵌版本, 这为RPC Software公司设计其需求功能 提供了起点。基于这点,Servlet.jar文件被移到他们自己开发的插件里。这样,其他被创建 的依赖servlet API的插件就可以使用它。已有的Tomcat插件在修改后使用Eclipse JDT编译 器,并非标准的Java编译器。因此CORE Business只需捆绑JRE而不是JDK。最后,用来加载包 含JSP页面的插件的类装载器,改进后被用来加载必要的系统插件,例如 org.eclipse.core.runtime。
package org.eclipse.help.internal.appserver;
public class PluginClassLoaderWrapper extends URLClassLoader {
...
/**
* This is a workaround for the jsp compiler that needs to know the
* classpath.
*/
public URL[] getURLs() {
Set urls = getPluginClasspath(_plugin);
return (URL[]) urls.toArray(new URL[urls.size()]);
}
private Set getPluginClasspath(String pluginId) {
// Collect set of plug-ins
Set plugins = new HashSet();
addPluginWithPrereqs(pluginId, plugins);
// Collect URLs for each plug-in
Set urls = new HashSet();
for (Iterator it = plugins.iterator(); it.hasNext();) {
String id = (String) it.next();
try {
Bundle b = Platform.getBundle(id);
if (b != null) {
// declared classpath
String headers = (String) b.getHeaders().get (Constants.BUNDLE_CLASSPATH);
ManifestElement[] paths =ManifestElement.parseHeader (Constants.BUNDLE_CLASSPATH, headers);
if (paths != null) {
for (int i = 0; i < paths.length; i++) {
String path = paths[i].getValue();
addBundlePath(urls, b, path);
}
} else {
// RPC custom code:
try { String bundleJarPath = b.getLocation();
if (bundleJarPath.equals(Constants.SYSTEM_BUNDLE_LOCATION)) {
SystemBundle systemBundle = (SystemBundle) b;
bundleJarPath = ((SystemBundleData) systemBundle.getBundleData()).getBundleFile().getBaseFile().toURL().getPath ();
bundleJarPath =bundleJarPath.substring (bundleJarPath.lastIndexOf("plugins/"));
} else if(bundleJarPath.startsWith("initial@reference:file:")) {
bundleJarPath =b.getLocation().replaceFirst ("initial@reference:file:", "");
} else {
bundleJarPath =b.getLocation().replaceFirst("update@", "");
}
if (bundleJarPath.endsWith("/")) {
bundleJarPath = bundleJarPath.substring(0, bundleJarPath.lastIndexOf("/"));
|