This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
There should be a way to programatically undeploy a webapp (like an undeploy method to mirror the deploy method in org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment). This would seem to make sense as part of the "clean" action for a web project. Use case #1: There are web frameworks out there that parse configuration files when the deployment occurs, but will not pick up changes to those files automatically. True, you can force a redeploy, but there's no way to return to a "clean" state now without traversing the Runtime..Servers UI. Use case #2: I'm working with a framework that uses log4j to output a log file in the web context, and it maintains a lock on that file until the context is undeployed. So, 'ant clean' does not work because it fails to delete the file. I went to modify my 'clean' ant target to undeploy the webapp first, and found no API to implement this. My workaround is to shut down the server altogether, which is much more time consuming.
Upon further searching, this is related to issue 32773. I just wrote an ant task that undeploys the current project's app. It seems to work all right, except that it will start up the server if it hasn't already launched, which is undesirable, but I haven't figured out how to check if the target j2ee server is running or not: public class UndeployTask extends Task { public void execute() throws BuildException { File baseDir = getProject().getBaseDir(); Project proj = FileOwnerQuery.getOwner(FileUtil.toFileObject(baseDir)); J2eeModuleProvider jmp = (J2eeModuleProvider) proj.getLookup().lookup(J2eeModuleProvider.class); DeploymentManager mgr = jmp.getInstanceProperties().getDeploymentManager(); // for tomcat, this target contains all the webapps Target target = jmp.getInstanceProperties().getDefaultTarget(); Target[] targets = { target }; String contextUrl = jmp.getConfigSupport().getWebContextRoot(); // (e.g. "/pizzaordering") try { TargetModuleID[] ids = mgr.getAvailableModules(ModuleType.WAR, targets); for (TargetModuleID id : ids) { String moduleId = id.getModuleID(); // (e.g. "http://localhost:8084/pizzaordering") if (moduleId.endsWith(contextUrl)) { log("Undeploying old build of web context: " + contextUrl); TargetModuleID[] toUndeploy = { id }; mgr.undeploy(toUndeploy); } } } catch (TargetException ex) { throw new BuildException(ex); } catch (IllegalStateException ex) { throw new BuildException(ex); } } }
I agree it would be good to add this into Deployment class and also to into nbdeploy task (or as a separate task). Not sure if you want to make it part of clean by default - if you clean/build repeatedly or if you have never deployed the module you do not want to be slowed down by undeploy (even connecting to the server and checking if it has been deployed), but we would need to test how long that takes. Maybe we can add a checkbox to Run tab in project properties. Undeploy would need to fail nicely (just show a waning) if the server is not running or if the module was not dpeloyed. Once we do this we should also add Undeploy action to project popup menu. I would then close 32773 as wontfix.
I added the following code at the beginning of the Task: ServerInstance si = ServerRegistry.getInstance().getServerInstance(jmp.getServerInstanceID()); StartServer ss = si.getStartServer(); if (ss == null || !ss.isRunning()) return; This required an impl dependency on j2eeserver (is there a way to check whether ss.isRunning() using API classes?) Clean is now very quick if the server isn't running at all. If it is running, but the webapp is not deployed, it is still very quick. I didn't notice any difference from the old behavior. In V-Builder, I plan to ship this Task, and to call it from the clean target. I would recommend a similar solution to NB, as well as taking a look at whether deploy should always force a redeploy (I think it should). If you think you might implement this the way I did, I could provide a full patch for web/project and j2eeserver.
Rich, yes please attach the diff. Stepan will take a look at this in 6.0.
Created attachment 33174 [details] Ant task for undeploying
Created attachment 33175 [details] patch for using UndeployTask.java
Thanks for the patch. Unfortunately, NB 5.5 is already feature frozen, so I will integrate your patch in the next release - 6.0.
Partially related to issue 112529.
Attaching the proper patch that should work for any J2EE module, doing nothing when app is not deployed or server is stopped.
Patch includes undeploy on clean.
Created attachment 69547 [details] patch
Created attachment 69663 [details] updated patch (minor fixes)
Fixed in main 5d7eec56a42d.