2016-11-20 133 views
0

我正在開發一個需要隨內置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時,它不工作。任何指針如何創建內置文件夾?

回答

1

您似乎期待src/weblogic/ant/目錄被包含在導出的插件jar中 - src目錄通常不包含在插件jar中。你想

認沽資源在一個單獨的目錄(如resources)的插件包括和包括在插件build.properties目錄,使其包含在導出插件的罐子。

+0

當我將build.xml移動到資源文件夾時,它的工作正常。但是,我需要在資源中放置更多文件夾,如jdbc模板,安全文件夾等。這些文件夾沒有被創建。我需要額外做些什麼來複制文件夾嗎? –

+0

您的代碼僅創建build.xml文件,您將不得不編寫代碼來創建所需的所有文件和文件夾。 –

相關問題