Java maven... 无法清理项目:无法删除 ..\org.ow2.util.asm-asm-tree-3.1.jar

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19489720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 17:42:18  来源:igfitidea点击:

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

javaeclipsespringmavenspring-tool-suite

提问by

I use STS(spring tool suite) + maven plugin.

我使用 STS(spring 工具套件)+ maven 插件。

Every time when I run my application using maven-cleanI see following error:

每次当我使用运行我的应用程序时,maven-clean我都会看到以下错误:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hhsystem ui 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ ui ---
[INFO] Deleting C:\Users\Nikolay_Tkachev\workspace\HHSystem\UI\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.471s
[INFO] Finished at: Mon Oct 21 12:34:33 MSK 2013
[INFO] Final Memory: 2M/90M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project ui: Failed to clean project: Failed to delete C:\Users\Nikolay_Tkachev\workspace\HHSystem\UI\target\org.ow2.util.asm-asm-tree-3.1.jar -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

I have to close STS and go to C:\Users\Nikolay_Tkachev\workspace\HHSystem\UI\targetand delete org.ow2.util.asm-asm-tree-3.1.jar

我必须关闭 STSC:\Users\Nikolay_Tkachev\workspace\HHSystem\UI\target并删除org.ow2.util.asm-asm-tree-3.1.jar

After starting STS again it works, but this is a hassle.

再次启动 STS 后它可以工作,但这是一个麻烦。

Can you help me with this problem?

你能帮我解决这个问题吗?

UPDATE
for Kalathoki L.


Kalathoki L 的更新

I run maven-cleanfrom this state:

maven-clean从这个状态跑:

STS screen shot

STS 屏幕截图

I see same behaviour from the command line as from the eclipse plugin

我从命令行看到了与 eclipse 插件相同的行为

If I watch unlocker when STS is running I see

如果我在 STS 运行时观看解锁器,我会看到

unlocker screen shot:

解锁器屏幕截图

回答by Yubaraj

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 serverthisicon 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 TerminateThis is an image of the Terminateicon in the toolbar.

  1. 在服务器视图(窗口 > 显示视图 > 其他 > 服务器 > 服务器 > 确定)中,选择要停止的服务器。
  2. 单击工具栏中的停止服务器这个图标。在服务器视图中,服务器的状态更改为已停止。
  3. 如果由于某种原因服务器无法停止,您可以按如下方式终止进程:

    一种。切换到调试透视图。

    湾 在进程视图中,选择要停止的服务器进程。

    C。单击 工具栏中的终止这是终止的图像图标。

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.

注意:当终止一个服务器时,服务器进程将结束,服务器不会经过正常的停止例程,例如调用 servlet 上的 destroy() 方法。

Source:Eclipse Help

来源:Eclipse 帮助

回答by Scorpio

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

您的问题是,当您执行mvn clean命令时,STS 中正在运行的进程正在使用位于目标目录中的文件。Maven 将无法删除这些文件(因为其他进程仍在访问它们),因此会因该错误而失败。

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.

尝试在运行 Maven 控制台命令之前停止 STS 中的所有进程(测试、服务器、应用程序)。注意:如果 STS 正在清理项目并因此重新编译源代码,而不是运行进程,则也可能出现此行为。

回答by vijucat

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

摘要:使用外部脚本(批处理文件)a) 停止服务器和 b) 在运行 maven-clean 之前解锁 .jar 文件。

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 handleutility download linkin the pre_clean.bat to a) stop the Tomcat server and b) unlock the .jar file. handle -cand handle -pwould be useful here.

  1. 将 maven-antrun-plugin:run 目标绑定到 mvn clean 的 pre-clean 阶段。在此处查看如何执行此操作

  2. 在此处查看如何使用 antrun 插件在 Windows 中运行外部批处理文件:sblundy 对“启动外部进程”的回答。让我们调用这个文件unlock_handles.bat

  3. 使用pre_clean.bat 中的Sysinternals 处理实用程序下载链接a) 停止 Tomcat 服务器和 b) 解锁 .jar 文件。handle -c并且handle -p在这里很有用。

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:

好的,这里有一个粗略的概念验证版本的 unlock_handles.bat 供您试用:

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.

当然,在尝试之前,您必须更改 Sysinternals 的 handle.exe 的路径。

回答by ram

For linux users: possible solution.

对于 linux 用户:可能的解决方案。

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

如果有机会仅提供给root用户而不是普通用户的删除访问权限,则会发生由于“无法删除 <任何文件或文件夹>”而导致的构建错误。

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

修复:输入ll命令列出无法删除的文件,如果文件被授予root权限,通过以下方式更改为普通用户:

sudo chown -R user-name:user-name filename

sudo chown -R 用户名:用户名文件名

Later try for maven clean and build.

稍后尝试 maven clean 和 build。

回答by Grim

If you lock org.ow2.util.asm-asm-tree-3.1.jarand 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.

如果您锁定org.ow2.util.asm-asm-tree-3.1.jar并启动 eclipse,日志将显示谁无法锁定文件。无法锁定文件的同一代码行不会释放锁定。

回答by Bartosz Bilicki

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

您也可以尝试尝试-Dmaven.clean.failOnError=false(来自Maven FAQ

回答by Raul Villalba

In pre-clean phase I execute with Maven Unlocker program. This program unlock all files and directory for anyone program.

在预清理阶段,我使用 Maven Unlocker 程序执行。该程序为任何程序解锁所有文件和目录。

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

我使用 maven-antrun-plugin 并且仅在 Windows 系统中执行此操作

<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>

回答by Davetron

Try disabling Project->Build Automatically.

尝试禁用 Project->Build Automatically。

As Scorpio suggested, there's a process running that's got a lock on a file somewhere.

正如 Scorpio 所建议的,有一个正在运行的进程在某处锁定了某个文件。

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.

我有一个大型的多模块 maven 项目,它经常在清理时失败,这为我解决了这个问题。完成后,我会重新启用“自动构建”。

回答by Madhu V Rao

I had similar issue. Earlier I was using Maven 3 to build the project. After switching to maven 2 , I had the above error.

我有类似的问题。早些时候我使用 Maven 3 来构建项目。切换到 maven 2 后,出现上述错误。

Solved it by switching to Maven 3.

通过切换到 Maven 3 解决了这个问题。

回答by Amir

I have same problem and this

我有同样的问题,这个

mvn clean install -U

command fixed the error.

命令修复了错误。