maven… Failed to clean project: Failed to delete ..\\org.ow2.util.asm-asm-tree-3.1.jar

走远了吗. 提交于 2019-11-30 03:02:37

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

    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

    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

You may also try try -Dmaven.clean.failOnError=false (from Maven FAQ)

Delete the java.exe process in Task Manager and run mvn clean install.It worked for me.

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.

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.

Regards!

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.

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

vijucat

Summary : Use an external script (batch file) that a) stops the server and b) Unlocks the .jar file before running maven-clean.

Steps:

  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.

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

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.

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.

I solved mine by doing:

  • mvn clean
  • mvn install
  • mvn clean install

For some reasons it worked for me . Good luck !!

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

<profile>
  <activation>
    <os>
      <family>windows</family>
    </os>
  </activation>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <phase>pre-clean</phase>
            <configuration>
              <tasks>
                <exec dir="${project.build.directory}" executable="cmd" failonerror="false">
                  <arg value="Unlocker.exe" />
                  <arg value="/S" />
                </exec>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!