0
我需要通過修改classpath條目將一些jar庫添加到帶有插件的項目中。但我找不到這樣做的方法。我試圖在我的插件的lib文件夾內嵌入jar lib,但是當插件打包爲Jar並部署在Eclipse IDE上時,我無法訪問它們。 任何解決方案? 什麼是正確的方法來做到這一點?將嵌入式插件jar文件添加到項目
這是添加的lib到目標項目代碼:
private void addLocalLibrary(IProject parent, String name, boolean source, boolean javadoc)
throws CoreException, URISyntaxException, IOException {
IClasspathEntry[] oldEntries = this.javaProject.getRawClasspath();
// +1 for our src/main/java entry
IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
String pluginDir = new File(Activator.getPluginDir()).getAbsolutePath().replace("file:", "");
IPackageFragmentRoot lib = this.javaProject.getPackageFragmentRoot(pluginDir + "/" + name);
IPackageFragmentRoot src = null;
if (source) {
src = this.javaProject.getPackageFragmentRoot((pluginDir + "/" + name).replace(".jar", "-sources.jar"));
}
IClasspathAttribute atts[] = null;
if (javadoc) {
IPackageFragmentRoot doc = this.javaProject
.getPackageFragmentRoot((pluginDir + "/" + name).replace(".jar", "-javadoc.jar"));
atts = new IClasspathAttribute[] {
JavaCore.newClasspathAttribute("javadoc_location", doc.getPath().toString()), };
}
IPath srcPath = src == null ? null : src.getPath();
newEntries[oldEntries.length] = JavaCore.newLibraryEntry(lib.getPath(), srcPath, null, null, atts, true);
this.javaProject.setRawClasspath(newEntries, null);
}
我知道這種可能性,但我如何使用這個庫插件將其包含在目標項目中? – Scandinave
@Scandinave你爲什麼不把它用作插件依賴? –
是的,我只是看到,我可以做到這一點。想想,我會努力。 – Scandinave