超越自我

          一切皆有可能

           

          Project 創(chuàng)建文件夾 和 文件 以及classpath

          創(chuàng)建工程:
          private IJavaProject project=null;
          public void createProject(IProgressMonitor monitor){
            try {
             BuildPathsBlock.createProject(getProject(),null, new SubProgressMonitor(monitor, 10));
            } catch (CoreException e) {
             e.printStackTrace();
            }
            project=JavaCore.create(getProject());
           }
          public IProject getProject()
              {
                  return ResourcesPlugin.getWorkspace().getRoot().getProject("ProjectName");
              }
          創(chuàng)建文件夾:
          public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
            if (!folder.exists()) {
             IContainer parent= folder.getParent();
             if (parent instanceof IFolder) {
              createFolder((IFolder)parent, force, local, null);
             }
             folder.create(force, local, monitor);
            }
           }
          創(chuàng)建文件:
          public void createMetaFile(IProgressMonitor monitor,String folder,String filename){
            StringWriter stringwriter = new StringWriter(1000);
            stringwriter.write("<config>xxx</config>");
            IFile ifile =getProject().getFile(filename);
                  byte abyte0[] = stringwriter.toString().getBytes();
                  ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(abyte0);
                  try{
                  if(!ifile.exists())
                      ifile.create(bytearrayinputstream, true, null);
                  else
                      ifile.setContents(bytearrayinputstream, true, false, null);
                  }catch(CoreException ex){
                   ex.printStackTrace();
                  }
           }
          創(chuàng)建classpath:
          public void createClassPath(IProgressMonitor monitor,String folder){
            ClasspathEntry aclasspathentry[] = new ClasspathEntry[2];
          //src 作為classpath
            IClasspathEntry srcClasspath = JavaCore.newSourceEntry(getProject().getFolder(folder).getFullPath());
            IClasspathEntry jrtClasspath = JavaRuntime.getDefaultJREContainerEntry();
            aclasspathentry[0] = (ClasspathEntry)srcClasspath;
                  aclasspathentry[1] = (ClasspathEntry)jrtClasspath;
                  if(aclasspathentry[1] == null)
                  {
                   jrtClasspath = JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER"));
                      aclasspathentry[1] = (ClasspathEntry)jrtClasspath;
                  }
            try {
             String natures[]=new String[] {
                      "org.eclipse.jdt.core.javanature"
                    };
          //添加 nature
             addNatures(natures,getProject(), new SubProgressMonitor(monitor, 10));
             createDirectory(monitor,folder);
          //設(shè)置味工程的classpath
             project.setRawClasspath(aclasspathentry, project.getPath().makeAbsolute().append(folder), new SubProgressMonitor(monitor, 5));
            } catch (JavaModelException e) {
             e.printStackTrace();
            } catch(CoreException e1){
             e1.printStackTrace();
            }
           }

          posted on 2005-11-02 13:05 jame 閱讀(918) 評(píng)論(0)  編輯  收藏 所屬分類: Eclipse JDT框架


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(3)

          隨筆檔案

          文章分類

          文章檔案

          相冊(cè)

          收藏夾

          UML

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 攀枝花市| 福清市| 友谊县| 宜兰市| 明星| 华宁县| 雷山县| 呼伦贝尔市| 寻甸| 安达市| 金寨县| 邢台市| 金沙县| 冕宁县| 高雄市| 金乡县| 漳平市| 湘潭县| 丁青县| 大埔县| 柘城县| 尤溪县| 迁安市| 巩留县| 安康市| 绵竹市| 福建省| 阳高县| 尖扎县| 兖州市| 呈贡县| 睢宁县| 松潘县| 贵州省| 沧源| 司法| 安图县| 六安市| 德格县| 昭平县| 新和县|