/** * This method will set the context root on the application for the passed in contextRoot. This * must be called in a write artifact edit and be saved for changes to be saved. * * @param webProject * @param aContextRoot */ public void setWebContextRoot(IProject webProject, String aContextRoot) { verifyOperationSupported(); if (webProject == null || !J2EEProjectUtilities.isDynamicWebProject(webProject)) return; IVirtualComponent webComp = ComponentCore.createComponent(webProject); String webModuleURI = getModuleURI(webComp); if (webModuleURI != null) { WebModule webModule = (WebModule) getApplication().getModule(webModuleURI, null); if (webModule != null) webModule.setContextRoot(aContextRoot); } } public IModelProvider create(IProject project) {
private void updateEARContextRoot(final IProject ear, final IProject project, final String newContextRoot, final IProgressMonitor monitor) { EARArtifactEdit earEdit = null; try { earEdit = EARArtifactEdit.getEARArtifactEditForWrite(ear); if (earEdit != null) { final Application application = earEdit.getApplication(); final IVirtualComponent comp = ComponentCore.createComponent(project); if (comp == null) { return; } final String moduleURI = earEdit.getModuleURI(comp); final Module module = application.getFirstModule(moduleURI); if (module != null && module instanceof WebModule) { ((WebModule) module).setContextRoot(newContextRoot); } earEdit.saveIfNecessary(monitor); } } finally { if (earEdit != null) { earEdit.dispose(); } } }
org.eclipse.jst.j2ee.application.WebModule webModule = org.eclipse.jst.j2ee.application.ApplicationFactory.eINSTANCE.createWebModule(); webModule.setUri(name); webModule.setContextRoot(contextroot); newModule = (ICommonModule)webModule;