7

I am getting the error:

[signjar] jarsigner: attempt to rename C:\workspace\line_editor\lib\icon.jar to C:\workspace\line_editor\lib\icon.jar.orig failed

when attempting to self sign a set of jars with ant inside Eclipse. The ant build has worked fine in this project and similar code in other projects. I made some small changes to code and tried to rebuild and keep getting this error.

Here is the related ant target:

<target name="sign" depends="jar" description="Signs Jars">

        <genkey keystore="myKeystore1" alias="something" storepass="somethingpass" 
          dname="CN=Classification, OU=NAPA, O=GPC, C=US"/> 


        <signjar keystore="myKeystore1" alias="something" storepass="somethingpass">
            <fileset file="${web.dir}/${jar.name}" />
            <fileset dir="${lib.dir}">
                <include name="*.jar"/>
            </fileset>  
        </signjar>
    </target>

I deleted the project and pulled it down again from our repository. So it has the same default project settings as other projects that this part does not fail. I looked at the .jar in question and it was not read-only. I changed the name and the next alphabetical .jar file also failed. There is no program running that is accessing the .jars in this folder.

Any suggestions as to cause?

jzd
  • 23,473
  • 9
  • 54
  • 76

3 Answers3

10

One possibility is that the jar - which is in a 'lib' directory - is on a classpath in use during your build. Is ${lib.dir} included on a classpath used in the buildfile?

You could create a separate directory to deposit signed jars to, and specify that to the 'signjar' task using the destdir attribute.

martin clayton
  • 76,436
  • 32
  • 213
  • 198
  • Yes I was also using it in the classpath higher in the build. I used your suggestion worked perfectly. Not sure why I have not had the problem in the past. – jzd Jan 17 '11 at 16:33
  • I noticed that this happened only when Netbeans (8.1, yes this is still an issue) was open and the jar was in its classpath. I had to remove the jar from the classpath AND restart netbeans to run jarsigner on it (or close netbeans and run it from another IDE). – Matteo Steccolini Sep 19 '16 at 15:42
2

I had the same problem. Try renaming the jar file yourself. If it can't be renamed, you can usually figure out which application has a file lock on it. Most likely some instance of java. Quit all java-based apps and try again. (Use task manager to make sure your java/javaw are not running.) After that, it should work.

bhlowe
  • 418
  • 4
  • 8
1

It looks for jarsigner.exe in the home directory of the JRE chosen for the project. If the JRE is just a JRE (not a JDK) this program will not be present.

Try setting a project-specific JRE and make sure it is actually a JDK.

finnw
  • 47,861
  • 24
  • 143
  • 221
  • As far as I can tell the JRE chosen is a JDK. Other projects work fine doing the same operation, I will keep digging into the project specific settings to see if I can find a difference. – jzd Jan 17 '11 at 14:42
  • I was able to find a more specific error message and updated my question. Looks like the jarsigner is having trouble renaming the .jar file. – jzd Jan 17 '11 at 14:58