/** * 创建包 * @param project 项目 * @param srcPath src路径 src 、 src/main/java * @param packageName * @return */ public static boolean createPackage(IProject project,String srcPath ,String packageName){ IJavaProject javaProject =JavaCore.create(project); try { IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(new Path("/"+project.getProject().getName() + srcPath)); root.createPackageFragment(packageName.toLowerCase(), true, null); project.refreshLocal(9, new NullProgressMonitor()); return true; } catch (JavaModelException e) { e.printStackTrace(); } catch (CoreException e) { e.printStackTrace(); } return false; }