I'm trying to automate the following situation on a Windows 7 workstation.

I use Java only for a single vendor app that requires the Java Cryptography Extension files to be placed in \security. However, everytime Java updates, a new folder is created referencing the build number of the Java and the JCE files have to be copied again into the new location.

I hoped JAVA might set an environment variable that pointed to the latest version, but it doesn't. The most it seems to do is update some SYMLINKS that point to the new version. However, since these are links to files, I don't think I can use them to move the JCE files.

My hope is to create a script that will grab the JCE files from a common location, discern the latest path for Java, and copy the JCE files into the proper place.

Any suggestions?

  • I'll have to get the full path for you. However, it's something like c:\program files(x86)\Java\java18_###\jre\lib\security where '###' is the build number that changes with each update applied to Java. So the path does change with each Java update. Thanks. – tcv Nov 21 '15 at 21:43
  • The old folder and files get removed. The JCE files need to be copied anew into the security directory under the new build number parent. – tcv Nov 21 '15 at 21:48
  • I have a static folder somewhere else that contains the JCE files, yes. Java leaves pieces of the old build folder structure but not the relevant folders like lib and security. Honestly I don't know why the update leaves anything behind as the only place I can put the JCE files is under the new build number folder structure. – tcv Nov 21 '15 at 21:53
  • Thanks, mate. I wonder if something as simple as copy c:\pathtojre*.* c:\program files(x86)\java\java18_???\jre\lib\security*.* would work? – tcv Nov 21 '15 at 21:58
  • 1
    I think the cleanest way is to figure out the highest build number and copy the files into the required spot. Copying into every build numbered folder would also work and, yes, the files are small. – tcv Nov 21 '15 at 22:06

Okay, here's a batch script that will find the Java folder with the highest version build number and then copy all files from your stage folder to the correct folder (with the highest version number only) as you need for the Java installed on your machine.

I also put some IF logic in there so if the \jre\lib\security directory does not exist, it creates it and then does the COPY command.

Save this to a text file and name with .cmd extension. You may need to run this as administrator as well as the C:\Program Files(x86)\Java folder may require administrator permissions to copy to it.

Sample Batch Script


SET StageDir=C:\pathtojre

CD /D %programfiles(x86)%\Java

FOR /F "TOKENS=*" %%F in ('DIR /B /AD /ON java*') DO (
    SET HighestNumDir=%%F

SET HighNumFullDir=%programfiles(x86)%\Java\%HighestNumDir%\jre\lib\security

IF NOT EXIST "%HighNumFullDir%" MD "%HighNumFullDir%"

COPY /Y "%StageDir%\*.*" "%HighNumFullDir%"
| improve this answer | |
  • WOW. Thank you. I'll check it out this weekend and let you know how it works. – tcv Nov 21 '15 at 22:41
  • It works! I had to make a couple of changes mostly due to my faulty memory of the paths involved but it works well. I know a bit of Python but batch scripts are a dark art. This is wonderful. Thank you. – tcv Nov 22 '15 at 1:28
  • Oh... there's no EOF label so that line always fails. – tcv Nov 22 '15 at 1:29
  • 2
    The EOF is End Of File so that just tells it to go to EOF so it's a dummy label. You can replace it with EXIT /B if you want.... Actually, I'll comment out the GOTO EOF and put in EXIT /B above. Glad it works for you and I appreciate the question as well, always up for a challenge. – Pimp Juice IT Nov 22 '15 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.