[英]Accessing java files from Eclipse source-bundle
如何从Eclipse / OSGI源包访问源代码?
我使用Maven / Tycho使用源功能包来生成源包。 这非常适合附加第三方开发的源代码。 它们在JAR上被称为“ Java源附件”的“外部位置”。
但是如何以编程方式到达源代码包? 源包不能作为常规包访问,即Platform.getBundle('com.myplugin.source')
,源文件也不能通过主包访问,即'com.myplugin'插件清单标头中也没有引用。 我应该使用Eclipse OSGI服务吗? 任何帮助,将不胜感激。
不是我希望的解决方案,但是作为一种解决方法,我可以直接转到源包JAR文件。 我希望有一个更好的解决方案,因为我不确定Oomph这样的方法是否可以证明未来。
String bloc = Platform.getBundle(bundlename).getLocation();
String location = bloc.replace(bundlename, bundlename+".source");
String path = new URL(location.replace("reference:", "")).getPath();
// Depending on installation type it may to prefix with Eclipse's installation path
if(!new File(path).exists())
path=Platform.getInstallLocation().getURL().getFile()+path;
File srcbundle = new File(path);
if(!srcbundle.exists()){
Logger.IDE.severe("Source bundle '"+path+"' not found!");
// When in runtime workbench we will get the source files from the bundle
for (URL url : Collections.list(bundle.findEntries("/", "*.*", true))) {
try(InputStream input = url.openStream()){
outputFile(input, url.getFile());
}
}
} else {
// When plugin installation we will unzip the source bundle JAR.
try(JarFile jar=new JarFile(srcbundle)){
for (JarEntry ze : Collections.list(jar.entries())) {
try(InputStream input = jar.getInputStream(ze)){
outputFile(input, ze.getName());
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.