Java – How to solve “Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project”

hibernatejavamaven

I am beginner in Maven. When I click clean & Build to rebuild my project in netbeans, it throws an error

Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project xxxx-web: Failed to clean project: Failed to delete D:\Gps2.x\xxxx-web\target\xxxx-web-2.11-SNAPSHOT\WEB-INF\lib\validation-api-1.0.0.GA.jar -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

Or how to build a war file using maven package?

Best Answer

This usually happens in Windows environments when the target folder is "locked". E.g. when you are running your web application (looks like you do) and want to perform a mvn clean. The application server/servlet engine locks the files so that mvn clean cannot delete the files because they are locked. Try to run this command when the web application is not running.

Edit: This also may happen if you have the target folder open in explorer or editing a text file from target folder, etc.