Groovy - Could not create SecurityManager
Posted by davidnewcomb on 13 Apr 2022 in Groovy
I haven't done any groovy for a while and when I ran my groovy command I got this:
$ groovy
Error occurred during initialization of VM
java.lang.Error: Could not create SecurityManager
at java.lang.System.initPhase3(java.base@11.0.2/System.java:2057)
Caused by: java.lang.ClassNotFoundException: allow
at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@11.0.2/BuiltinClassLoader.java:583)
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@11.0.2/ClassLoaders.java:178)
at java.lang.ClassLoader.loadClass(java.base@11.0.2/ClassLoader.java:521)
at java.lang.Class.forName0(java.base@11.0.2/Native Method)
at java.lang.Class.forName(java.base@11.0.2/Class.java:398)
at java.lang.System.initPhase3(java.base@11.0.2/System.java:2042)
I reinstalled groovy with brew reinstall groovy
but it didn't make any difference. After a bit of Googling I found a solution.
- Locate your groovy executable. Mine is in
/usr/local/bin/groovy
- Load it into your favourite editor and modify the security manager name from java.security.manager to java.security.SecurityManager, as follows:
JAVA_HOME="${JAVA_HOME:-/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home}" JAVA_OPTS="$JAVA_OPTS -Djava.security.manager=allow" exec "/usr/local/Cellar/groovy/4.0.1_1/libexec /bin/groovy" "$@"
to
JAVA_HOME="${JAVA_HOME:-/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home}" JAVA_OPTS="$JAVA_OPTS -Djava.security.SecurityManager=allow" exec "/usr/local/Cellar/groovy/4.0.1_1/libexec /bin/groovy" "$@"
That's it! Do the same for the other groovy supporting programs like: groovyConsole, groovyConsole_completion, groovy_completion, groovyc, groovyc_completion, groovydoc, groovydoc_completion, groovysh, groovysh_completion, also located in /usr/local/bin
.
2 comments
Comment from: Matt [Visitor]
Comment from: Ujjwal [Visitor]
This is correct answer +1
Form is loading...
I want to thank you for this post - it saved me a lot of time and trouble.
I was surprised why a Homebrew package would be so broken, so I did some digging about the root cause… I can’t say what the root cause is for you, but for me it’s because I had $JAVA_HOME set to a Java 11 implementation. Support for
-Djava.security.SecurityManager=allow
seems to have been added in Java 12. Search for “allow” (including quote marks) [here](https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/lang/SecurityManager.html) vs [here](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/SecurityManager.html)