【问题标题】:How to create a builtin file and folder in custom eclipse plugin如何在自定义 Eclipse 插件中创建内置文件和文件夹
【发布时间】:2016-11-21 00:14:25
【问题描述】:

我正在开发一个需要附带内置 ant 构建文件的 Eclipse 插件。它在我运行项目时工作。但是,当我在另一个 Eclipse 中导出插件并部署导出的插件时,没有生成 ant 构建文件。我的怀疑是在运行时,没有访问ant构建文件的源。任何指针如何解决这个问题?这是代码:

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(filePath) 行打印路径为 /C:/Users//Desktop/eclipse-rcp-luna-SR2-win32-x86_64/eclipse/../../../workspace-plugin/weblogic/resources/weblogictemplate/

所以,它在本地工作。但是,当我在其他 Eclipse 中部署 pluin 时,它不起作用。任何指针如何创建内置文件夹?

【问题讨论】:

    标签: eclipse eclipse-plugin eclipse-rcp


    【解决方案1】:

    您似乎希望 src/weblogic/ant/ 目录包含在导出的插件 jar 中 - src 目录通常不包含在插件 jar 中。

    将要包含在插件中的资源放在单独的目录中(例如resources),并将该目录包含在插件build.properties 中,以便包含在导出的插件jar 中。

    【讨论】:

    • 当我将 build.xml 移动到资源文件夹时,它工作正常。但是,我需要在资源中放置更多文件夹,例如 jdbc 模板、安全文件夹等。这些文件夹没有被创建。我需要做一些额外的事情来复制文件夹吗?
    • 您的代码只是创建 build.xml 文件,您必须编写代码来创建您需要的所有文件和文件夹。
    猜你喜欢
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 2012-01-26
    相关资源
    最近更新 更多