7

I'm trying to run simple struts project using maven and tomcat.

When I'm trying to exucute next goals: clean install tomcat7:run I'm getting MojoExecutionException :

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean
(default-clean) on project myproject: Failed to clean project: Failed to delete
D:\EclipseWorkspace\myproject\target\tomcat\logs\access_log.2015-02-21
-> [Help 1]

I've googled and understand that tomcat uses this access_log file, where he logs user requests. And by the time when I want to execute goals listed above, as I'm using Eclipse IDE, the JVM denies for deleting this file.

I saw same questions: Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1, Maven - Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean.

But don't understand the proposed solutions to such problem.

Community
  • 1
  • 1
marknorkin
  • 3,904
  • 10
  • 46
  • 82
  • 2
    Have you stopped Tomcat before clean? If not this is a typical problem on Windows, cause if the file is being used windows will lock that file and you can't delete it. – khmarbaise Feb 21 '15 at 18:40
  • @khmarbaise yes, i've tested for such a case. it is not a cause – marknorkin Feb 21 '15 at 18:53

4 Answers4

23

I've seen this sort of error whenever there's a process that's holding a lock on a file in some subfolder that Maven is trying to clean. Check that your Tomcat instance is really stopped (look for java processes in Task Manager that shouldn't be there). I've also created this issue for myself by opening the access log in a text editor, and then forgetting to close the editor after shutting down the Tomcat and trying to run a new build.

Michael Peacock
  • 2,011
  • 1
  • 11
  • 14
  • No, this is not the case. File is not open and tomcat is stopped – marknorkin Feb 21 '15 at 18:58
  • In my case I am experiencing this issue with sonar scanner apparently not releasing resources properly - this results in an error during cleanup. https://github.com/spotbugs/spotbugs/pull/591 – NicolasW May 04 '18 at 17:33
3

Micahel Peacock and khmarbaise were right about some proccess is blocking the deletion.

This is some tip for maven newbies, like me.

I've faced such problem, because after running Tomcat with maven goals clean install tomcat7:run I stopped it either through shutdown batch file in ${CATALINA_HOME}/bin directory or through installed Eclipse Tomcat plugin by clicking on the next label:

menu panel

But to do it in the right way you should click on stop label in console view:

console view

Then locale tomcat instance will be stopped and no such errors would appears, because proccess will shutdown gracefully.

marknorkin
  • 3,904
  • 10
  • 46
  • 82
1

In my case it was a different program than Tomcat blocking a folder that should be deleted. Here is my approach based on the answer of Michael Peacock:

This way you on Windows 10 you can find out which process blocks the file or folder:

  1. Search for "Resource Monitor"
  2. Go to the tab "CPU"
  3. Scroll down to "Associated Handles"
  4. Search for the file or folder in the search bar of that tab.
  5. Kill the process, if you think this is the blocking one.

If you do not know which file can not be deleted check Maven's log. There it tells you which file or or folder it was deleting before the error occurred. Most likely this is the one that caused the problem.

Hendrik
  • 413
  • 7
  • 17
  • 1
    Thanks for the solution. I was trying to find something like this. Many times I had to restart the system to resolve this but now I can do it without restarting. Thanks – O_K Jul 14 '21 at 07:00
  • I am glad that the instructions were helpful for you! – Hendrik Jul 14 '21 at 09:31
0

I had the same problem in Fedora. In my case owner of targe directory was changed to root usring --> [chown your-username target] I fix it.

mohsen.nour
  • 1,089
  • 3
  • 20
  • 27