6

I have a maven project in eclipse indigo with m2e 1.2.0.20120903-1050 maven plugin. That project contains maven system dependencies and these jar files are checked into git repository.

That is all fine until I need to switch to another branch which has changes in system dependencies. Git can not update contents as file is locked.

That seems that eclipse on its own or on behalf of m2e locked jar libraries. I tried closing project but that does not help, in order to release lock I have to restart eclipse.

That is rather cumbersome. Are there any trick to release lock without restarting eclipse?

michael nesterenko
  • 14,222
  • 25
  • 114
  • 182

6 Answers6

5

Windows

You can manualy use handle.exe from http://technet.microsoft.com/de-de/sysinternals/bb896655.aspx

  1. handle.exe .jar gives you a list by handle-id and process-id of all jar's.
  2. handle.exe -c <handle-id> -p <process-id> kills the Handle, maybe a exception will be thrown, if so, fill a bug-report to Eclipse's bug-report-system please to let us know about dead-locks.

EDIT:

It is important to execute the command using Administrator rights (Thanks to Paulo Merson).

Grim
  • 1,938
  • 10
  • 56
  • 123
  • I tried handle. It was useful to confirm that Eclipse is indeed the process keeping the lock. However, `handle -c -p ` did not work. It asked for confirmation, but at the end the message was "Error closing handle: invalid identifier". – Paulo Merson May 30 '18 at 14:08
  • 1
    @PauloMerson hm, I am wondering what identifier is meant. Maybe the file-lock-identifier. A invalid identifier is a identifier who does not point to a file-lock anymore. Maybe the lock is gone. Could you check if the handle-id changes rapidly? – Grim May 30 '18 at 18:12
  • 1
    I first called `handle C:\\myjar.jar`. The output showed `eclipse.exe pid: 20272 type: File 1314: C:\\myjar.jar`. There's no clear indication of what is the handle id, but by exclusion I assumed it is `1314`. So I tried `handle -c 1314 -p 20272`, got a confirmation question `Close handle 1314 in eclipse.exe (PID 20272)? (y/n)`, answered yes, but got `Error closing handle: The handle is invalid`. – Paulo Merson Jun 01 '18 at 17:50
  • 1
    This is very interesting and your assumptation seems correct. 1314 is very low. The pid meant to be periodicaly increased but the value is pretty low. I dont think anymore the handle-id changes rapidly. Another reason might be the windows rights. Can you execute the command-line as an administrator? – Grim Jun 01 '18 at 19:59
  • 1
    BINGO! When I open the command-line as administrator, `handle` closes the handle. (Worth a note in your answer if you will.) – Paulo Merson Jun 04 '18 at 13:08
3

It's not a problem with Windows. It's a problem with something Eclipse is doing. It's keeping the file open for the duration of the Eclipse runtime. That is a horrible practice.

Paulo Merson
  • 13,270
  • 8
  • 79
  • 72
Ryan
  • 658
  • 6
  • 6
2

You can download the Sysinternals Suite from Microsoft and make use of the handle.exe or procexp.exe program to find which program has a handle on the jar. It appears to be safe to close the handle in Eclipse (I've not noticed any side-effects).

It's documented on the sysinternals site how to use handle.exe and for procexp.exe use the Find -> Find Handle or DLL menu option. Type the name of the locked jar file, then select the locking process in the sub-window. In the main window it should show a handle to the file within a process, you can check the process is what you think it is, then right click the handle and choose Close Handle.

You should run both these tasks with administrator rights.

There are other guides also available on the net:

mrswadge
  • 1,659
  • 1
  • 20
  • 43
1

No. If the files are open, git cannot remove them. This is a windows thing.

I would suggest you instead install them in your local repository, instead of dealing with system scope,

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Jar files are used in legacy ant build scripts, so I can not make changes to them. I would like somehow tell eclipse to release locks without restarting :) – michael nesterenko Feb 20 '13 at 22:13
  • Try closing the projects. In your situation I would not switch branches in the same workspace but have a separate workspace for each branch. – Thorbjørn Ravn Andersen Feb 20 '13 at 22:20
  • Closing does not help, I tried. I moved to one workspace for many branches deliberately as it simplifies switching among different project versions. That would be too much workspaces if I created it for each branch made. – michael nesterenko Feb 21 '13 at 00:56
  • Currently I have 3 branches I work with and about 10 branches that I use from time to time. – michael nesterenko Feb 21 '13 at 09:29
  • Our branches vary wildly - I have found that Eclipse does not cope well with varying submodules in the branches - so I simply have a workspace pr branch. With as few as you have there, I would do the same if I were you. Maven is simply not yet a first class citizen of Eclipse and all the handwaving done by m2e does not cover this completely. That said, I would suspect your ant tasks for this - do you run all maven and ant tasks in a forked jvm? – Thorbjørn Ravn Andersen Feb 21 '13 at 10:17
1

I have had issues with this as well. It turns out this is caused by Windows indexing files. I am using Windows 7. I went to the control panel and selected Indexing options. I made sure to remove any folder that my code was located in. That solved my problem.

jwesley
  • 91
  • 4
0

I have the same issues using RAD(eclipse) at work. In my case it happens when decompiling with the JD-Eclipse (1.0.0) plugin. I don't have issues when installing the latest Eclipse Mars (4.5.1) and JD-Eclipse (1.0.0). I suspect the underlying version of eclipse (4.2.1) in the version of RAD at work are incompatible with JD-Eclipse (1.0.0).

Community
  • 1
  • 1