当前位置: 代码迷 >> Eclipse >> Eclipse插件开发之动态创办source folder
  详细解决方案

Eclipse插件开发之动态创办source folder

热度:66   发布时间:2016-04-23 02:08:28.0
Eclipse插件开发之动态创建source folder

try {

// 先找指定的源文件夹所在的IPackageFragmentRoot

final IProject project = root.getProject(projectName);

IJavaProject javaProject = JavaCore.create(project);

IFolder srcFolder = javaProject.getProject().getFolder("src");

? ? ? ? srcFolder.getName();

? ? ? ? if(!srcFolder.exists()){

srcFolder.create(true, true, null);

? ? ? ? }

IPackageFragmentRoot packageFragmentRoot = javaProject

.findPackageFragmentRoot(new Path("/"+projectName+"/src"));

// 根据IPackageFragmentRoot创建IPackageFragment,IPackageFragment就是包了

if(packageFragmentRoot != null){

IPackageFragment packageFragment = packageFragmentRoot

.createPackageFragment(packageSrcName, true, null);

System.out.println(packageFragment.toString());

} else

throwCoreException( projectName + "下不存在src文件夹,请手动创建." );

} catch (JavaModelException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

  相关解决方案