开发者

How to add dynamic webprojects to an EAR programmatically in Java?

I created a dynamic web project. I want 开发者_开发知识库to add this to an ear project. I want this EAR project to be created programmatically and add some additional facets to it and add dynamic web project to that EAR.

What i have done now is, created a web project and added below property to add that to an EAR project.

iDataModel.setBooleanProperty(IWebFacetInstallDataModelProperties.ADD_TO_EAR ,true);

This will create EAR with default settings. But i dont want this. I want to create EAR project and add some more IBM facets to it. so i created an EAR as below.

IDataModel earModel = DataModelFactory.createDataModel(new EARFacetProjectCreationDataModelProvider()); earModel.setProperty(IFacetDataModelProperties.FACET_PROJECT_NAME, projName); earModel.getDefaultOperation().execute( monitor, null);

with this i can add some additional facets to this EAR project. But i dont know how to add web project to this EAR.

Help me if anyone came across this scenario.


I got this worked finally. In this way, we can choose desire list of web and java projects to be added to a one or more EAR projects programmatically.

public void createEARProject(IProject iEARProj, IProject iWebProj, IProgressMonitor monitor) throws ExecutionException, CoreException{

IProjectDescription earProjectDesription = ResourcesPlugin.getWorkspace().newProjectDescription(iEARProj.getName()); iEARProj.create(earProjectDesription, monitor); iEARProj.open(monitor);

final IFacetedProject earFacetedProject = ProjectFacetsManager.create(iEARProj, true, monitor); IActionDefinition earInstallAction = EARFacetUtils.EAR_14.getActionDefinition(Collections.singleton(EARFacetUtils.EAR_14), IFacetedProject.Action.Type.INSTALL); IDataModel earConfig = (IDataModel) earInstallAction.createConfigObject(EARFacetUtils.EAR_14, iEARProj.getName());

earConfig.setProperty(IEarFacetInstallDataModelProperties.J2EE_PROJECTS_LIST, Arrays.asList(new IProject[]{iWebProj})); earConfig.setProperty(IEarFacetInstallDataModelProperties.JAVA_PROJECT_LIST, Collections.EMPTY_LIST); earConfig.setBooleanProperty(IFacetDataModelProperties.SHOULD_EXECUTE, Boolean.TRUE);

IDataModel master = DataModelFactory.createDataModel(new EARFacetProjectCreationDataModelProvider()); master.setStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME, earConfig.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME)); master.setProperty(IFacetProjectCreationDataModelProperties.FACET_DM_MAP, Collections.singletonMap(EARFacetUtils.EAR_FACET.getId(), earConfig)); master.setProperty(IFacetProjectCreationDataModelProperties.FACET_ACTION_MAP, Collections.EMPTY_MAP); master.setProperty(FacetProjectCreationDataModelProvider.REQUIRED_FACETS_COLLECTION, Collections.singletonList(EARFacetUtils.EAR_FACET));

earConfig.setProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM, master);

earFacetedProject.installProjectFacet(EARFacetUtils.EAR_14, earConfig, monitor); earFacetedProject.setFixedProjectFacets(Collections.singleton(EARFacetUtils.EAR_FACET));

}

Hope this helps if anyone trying the way i tried.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜