如何在自定义eclipse插件中创建内建文件和文件夹
问题描述:
我正在开发一个需要随内置ant构建文件一起发货的Eclipse插件。它在我运行项目时工作。但是,当我导出插件并在另一个eclipse中部署导出的插件时,不会生成ant构建文件。我的怀疑是,在运行时,ant编译文件的来源不被访问。任何指针如何解决这个问题?下面是代码:如何在自定义eclipse插件中创建内建文件和文件夹
private void createAntFile(IProject project, Properties properties) throws CoreException, IOException {
InputStream antFileInputStream =null;
try {
String antFileName = properties.getProperty("name.ant.file");
String antFilePath = properties.getProperty("path.ant.file");
IFile file = project.getFile(antFileName);
antFileInputStream = Activator.getDefault().getBundle().getEntry(antFilePath).openStream();
file.create(antFileInputStream, false, null);
antFileInputStream.close();
}finally{
if(antFileInputStream!=null){
try {
antFileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
name.ant.file=build.xml
path.ant.file=src/weblogic/ant/build.xml
该人士构建文件我在路的src/weblogic的硬编码/ ANT/build.xml文件
编辑:
这里是代码创建内置文件夹:
private void createWeblogicTemplate(IProject project, Properties properties) throws IOException, CoreException {
String weblogicTemplateSourcePath = properties.getProperty("path.weblogic.template.source");
Path path = new Path(weblogicTemplateSourcePath);
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
URL fileURL = FileLocator.find(bundle, path, null);
String filePath = FileLocator.resolve(fileURL).getPath();
System.out.println(filePath);
File sourceFile = new File(filePath);
String weblogicTemplateTargetPath = properties.getProperty("path.weblogic.template.target");
IFolder folder = project.getFolder(weblogicTemplateTargetPath);
copyFolder(sourceFile,folder,project,properties);
}
线的System.out.println(文件路径)是印刷路径作为 /C:/Users//Desktop/eclipse-rcp-luna-SR2-win32-x86_64/eclipse/../../../workspace-plugin/weblogic/resources/weblogictemplate/
因此,本地它的工作。然而,当我在其他日食中部署pluin时,它不工作。任何指针如何创建内置文件夹?
答
您似乎期待src/weblogic/ant/
目录被包含在导出的插件jar中 - src目录通常不包含在插件jar中。你想
认沽资源在一个单独的目录(如resources
)的插件包括和包括在插件build.properties
目录,使其包含在导出插件的罐子。
当我将build.xml移动到资源文件夹时,它的工作正常。但是,我需要在资源中放置更多文件夹,如jdbc模板,安全文件夹等。这些文件夹没有被创建。我需要额外做些什么来复制文件夹吗? –
您的代码仅创建build.xml文件,您将不得不编写代码来创建所需的所有文件和文件夹。 –