for me

mvn install
mvn clean install



if you lock org.ow2.util.asm-asm-tree-3.1.jar and start eclipse, the logging shows who was unable to lock the file. the same codeline who cant lock the file will not release the lock.


in pre-clean phase i execute with maven unlocker program. this program unlock all files and directory for anyone program.

i execute this with maven-antrun-plugin and only in windows systems

                <exec dir="${}" executable="cmd" failonerror="false">
                  <arg value="unlocker.exe" />
                  <arg value="/s" />


please close all the browser tab. and next time when you try to upload war from another place except target folder.


if you run into this error in an ide like eclipse or intellij, you may have one or more debug windows open and paused on a break-point. terminate them.


the reason for this error is, the file which maven is trying to delete is being used by some process. one example of such process is eclipse or any other ide is doing validation on same project.

please make sure that no validation running from eclipse or in any other ide where project is open.


  1. i closed git bash (might be another terminal you are working on). it stops the process
  2. delete ...0.0.1-snapshot.jar
  3. mvn clean install (or other start your project command; we have .sh)


if you have a process running that using the packaged app deployed like an ftp or ssh session - it could prevent the resource being deleted or moved:

so identify the open port which is using the war or jar, close it - then restart

sftp - ssh port : 22

ssh port : depend on config


i had similar issue. earlier i was using maven 3 to build the project. after switching to maven 2 , i had the above error.

solved it by switching to maven 3.


maven complains if you do not have admin permissions on the target folder.check if you have admin right to delete that folder.

enter image description here


i solved mine by doing:

  • mvn clean
  • mvn install
  • mvn clean install

for some reasons it worked for me . good luck !!


for linux users: possible solution.

build error due to "failed to delete < any-file-or-folder >" will occur if there is by chance of only delete access provided to root user rather to normal-user.

fix : type ll command to list file that cannot be deleted, if the file is given root access, change to normal user by :

sudo chown -r user-name:user-name filename

later try for maven clean and build.


solved by deleting the target folder manually.


if all steps (in existing answers) dont work , just close eclipse and again open eclipse .


summary : use an external script (batch file) that a) stops the server and b) unlocks the .jar file before running maven-clean.


  1. bind the maven-antrun-plugin:run goal to the pre-clean phase of mvn clean. see how to do this here

  2. see how to use the antrun plugin to run an external batch file in windows here : sblundy's answer to "starting external process". let's call this file unlock_handles.bat

  3. use the sysinternals handle utility download link in the pre_clean.bat to a) stop the tomcat server and b) unlock the .jar file. handle -c and handle -p would be useful here.

whew! that's a bit of work, but it will reliably automate the process for you so that you do need to do it manually yourself each time!

ok, here's a rough, proof-of-concept version of unlock_handles.bat for you to try out:

rem "use handle.exe to figure out the process id and handle ids, parse the output, then close the handle (again using handle.exe)"

cd "c:\users\nikolay_tkachev\workspace\hhsystem\ui\target"
"c:/program files/process explorer/handle.exe" -p java.exe "c:\users\nikolay_tkachev\workspace\hhsystem\ui\target" > handles.txt

@echo "o====== going to unlock all the below file handles! =======o"
for /f "tokens=1-26 delims=: " %a in (handles.txt) do @echo %h
for /f "tokens=1-26 delims=: " %a in (handles.txt) do handle -p %c -c %f -y

of course, you have to change the path to sysinternals' handle.exe before giving this a try.


i have same problem and this

mvn clean install -u

command fixed the error.


try disabling project->build automatically.

as scorpio suggested, there's a process running that's got a lock on a file somewhere.

i have a large multi-module maven project that regularly fails on clean and this resolves it for me. i re-enable build automatically when i'm done.


probably there are many processes that use sources compiled, could be a server, an old maven instruction or ide. sure terminate all processes, stop the server and then execute maven again. if the problem persists, you should close java.exe process.



close the target folder and its file you have opened before mvn clean


your problem is that a running process within sts is using files located in your target directory while you execute a mvn clean command. maven will be unable to delete these files (since other processes are still accessing them) and thus fail with that error.

try to stop all processes (tests, servers, applications) from within sts before running maven console commands. look out: this behaviour might also appear if sts is cleaning up the projects and thus re-compiles the sources, and not running a process.


delete the java.exe process in task manager and run mvn clean worked for me.


you may also try try -dmaven.clean.failonerror=false (from maven faq)


stop your server before you start to clean.

stopping a server

you can stop the server from the servers view.

to stop the server:

  1. in the servers view ( window > show view > other > server > servers > ok), select the server that you want to stop.
  2. click the stop the server this icon in the toolbar. in the servers view, the status of the server changes to stopped.
  3. if for some reason the server fails to stop, you can terminate the process as follows:

    a. switch to the debug perspective.

    b. in the process view, select the server process that you want to stop.

    c. click the terminate this is an image of the terminate icon in the toolbar.

note: when terminating a server, the server process will end and the server will not go through the normal routine of stopping, for example calling the destroy() method on a servlet.

source: eclipse help

Related Query