[tip] Enable Maven Dependency Management
Hi,
各位版有好。最近剛好需要做一個功能,
建立自己的 Java Project 並自動啟用 Maven 相依性管理。
把目前由 mail list 上獲得的資訊與測試後可行的 code 整理如下:
/**
* enable project maven dependency management
* @param project the project must has pom.xml
* @throws CoreException
*/
private void enableMavenDependencyManagement(IProject project)
throws CoreException {
ResolverConfiguration configuration = new ResolverConfiguration();
configuration.setIncludeModules(false);
configuration.setResolveWorkspaceProjects(true);
configuration.setActiveProfiles("");
boolean hasMavenNature = project.hasNature(IMavenConstants.NATURE_ID);
IProjectConfigurationManager configurationManager = MavenPlugin
.getDefault().getProjectConfigurationManager();
configurationManager.enableMavenNature(project, configuration,
UIUtilz.NULL_PROGRESS_MONITOR);
if (!hasMavenNature) {
configurationManager.updateProjectConfiguration(project,
configuration, MavenPlugin.getDefault()
.getMavenRuntimeManager().getGoalOnUpdate(),
new NullProgressMonitor());
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.133.80.216
Eclipse 近期熱門文章
PTT數位生活區 即時熱門文章