How would I use Maven to install the JCE Unlimited Strength Policy files?

Jeff Martin picture Jeff Martin · Aug 6, 2010 · Viewed 16.5k times · Source

Some code I have requires the JCE unlimited Strength Policy Files. I'd like to add this dependency into the Maven Pom file so the other developers on my team don't have to individually each apply this to their systems.

I realize that the systems this is eventually deployed to will need to have the JCE files manually installed. This is a development solution only.

I was thinking that we would add the policy files to our repository and maven would be able to handle installation, but I am surprised that I can't find anyone else doing this (and blogging about it.).

Answer

Bart Prokop picture Bart Prokop · Nov 29, 2013

I've found that answer, when googling for Maven dependencies for policy JARs and realized that it's JRE installation specific, thus fixing this as part of Maven build will work only for developers and only when you have rights to /jre/lib/security folder. For me the following code hack works much better (invoke this as one of the very first things your application does):

    try {
        Field field = Class.forName("javax.crypto.JceSecurity").getDeclaredField("isRestricted");
        field.setAccessible(true);
        field.set(null, java.lang.Boolean.FALSE);
    } catch (ClassNotFoundException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
        ex.printStackTrace(System.err);
    }