Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 338526 - can not delete war file in webapps
Summary: can not delete war file in webapps
Status: RESOLVED WORKSFORME
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: 7.2.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 7.2.x   Edit
Assignee: Greg Wilkins CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-01 07:18 EST by weijx CLA
Modified: 2011-05-11 11:04 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description weijx CLA 2011-03-01 07:18:06 EST
when I start jetty7,I can copy war to webapps folder,but I can not delete it.
i think there is some file handler not close.I write a test java file, the result is that i can not delete AJspWar.war.

-------------------------------------------------------
import java.io.File;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.JarResource;
import org.eclipse.jetty.util.resource.Resource;

public class TestDeleteFile {

	public static void main(String[] args) throws Exception{
		String war = "d:\\test\\AJspWar.war";
		Resource res = Resource.newResource(war);
		res = JarResource.newJarResource(res);
		
		Resource web_inf= res.addPath("WEB-INF/");

        File extractedWebInfDir= new File("d:\\test\\webinf");
        if (extractedWebInfDir.exists())
            IO.delete(extractedWebInfDir);
        extractedWebInfDir.mkdir();
        Resource web_inf_lib = web_inf.addPath("lib/");
        File webInfDir=new File(extractedWebInfDir,"WEB-INF");
        webInfDir.mkdir();

        if (web_inf_lib.exists())
        {
            File webInfLibDir = new File(webInfDir, "lib");
            if (webInfLibDir.exists())
                IO.delete(webInfLibDir);
            webInfLibDir.mkdir();

            Log.info("Copying WEB-INF/lib " + web_inf_lib + " to " + webInfLibDir);
            web_inf_lib.copyTo(webInfLibDir);
        }

        Resource web_inf_classes = web_inf.addPath("classes/");
        if (web_inf_classes.exists())
        {
            File webInfClassesDir = new File(webInfDir, "classes");
            if (webInfClassesDir.exists())
                IO.delete(webInfClassesDir);
            webInfClassesDir.mkdir();
            Log.info("Copying WEB-INF/classes from "+web_inf_classes+" to "+webInfClassesDir.getAbsolutePath());
            web_inf_classes.copyTo(webInfClassesDir);
        }

        web_inf=Resource.newResource(extractedWebInfDir.getCanonicalPath());

        File warFile = new File(war);
        if(warFile.delete()){
        	System.out.println("delete success");
        }else{
        	System.out.println("delete failure");
        }
	}

}
Comment 1 Nikolas Falco CLA 2011-03-23 09:49:11 EDT
in this example missing a few of Resource.release(); before execute delete.

Also after relesing them same problem, but I think it's NORMAL that in a application server you can't delete ear/war.

You can update it (and will be redeployed automatically), already try and works.
Comment 2 Jesse McConnell CLA 2011-05-11 11:04:17 EDT
looks like your using windows which is always a problem with java files and deletes, just a mess

anyway, typically if your looking to manage that sort of lifecycle with a webapp I would recommend you use the context deployment mechanism where you have descriptors in the contexts directory that point to a war file, but I just tested this out on my linux box it it works both ways, removing the context file and having the app undeploy, and removing the war file and having the app undeploy.

I suspect the context approach might work for you on windows, give it a shot and if it doesn't reopen the issue and we'll see about looking at the windows issue

that or its simply this issue: http://docs.codehaus.org/display/JETTY/Files+locked+on+Windows