6
votes

I am attempting to run a https site using grails 2.4.4 with tomcat plugin :

build ':tomcat:7.0.55.2'

Upon first attempt to launch the app I hit the following issue: issue 648

java.lang.ClassNotFoundException: com.ibm.crypto.tools.KeyTool

When I change the tomcat dependency for tomcat to tomcat 8.0.22 and run app again it succeeds and goes beyond i.e. createSSLCertificate(File keystoreDir) works and although the app does not start up. If I now change it back to tomcat 7.0.55.2 the keys have been generated and the app works.

I guess the question is I was unsure if that fix that Graeme has pointed to only exists in tomcat 8 or is there a later version of tomcat 7 I could use that has a fix for this problem.

Whilst this hack is ok for a development machine, I really need something more concrete for when the app is built via jenkins etc.

To recreate this locally, if I do a

grails clean-all 

and try

grails run-app -https 

I hit the issue for the very first time until I repeat the above steps again.

Thinking about it Jenkins producing a WAR file may actually be fine, although from a development point of view it still be nice to find a nicer way of making this all work.

1
did you try\can you upgrade to grails 2.5.x? - shaydel
That was where I started. I hit this issue grails.1312388.n4.nabble.com/… with forking disabled: Error creating bean with name 'defaultGrailslongConverter'.. anyways so far as I am aware grails 2.5 still points to tomcat 7 and not 8. The issue here relates to a fix put in tomcat 8. - V H

1 Answers

6
votes

I've run into this problem myself aswell. I have tried some other solutions I found on the internet until I stumbled on https://github.com/grails/grails-profile-repository/pull/14/files This did the trick for me to solve this issue and run my application with -https

Go to TomcatServer.groovy, and replace:

protected getKeyToolClass() {
    try {
        Class.forName 'sun.security.tools.KeyTool'
    }
    catch (ClassNotFoundException e) {
        // no try/catch for this one, if neither is foun\d let it fail
        Class.forName 'com.ibm.crypto.tools.KeyTool'
    }
}

with:

protected Class getKeyToolClass() {
    try {
        try {
            // Sun JDK 8
            return Class.forName('sun.security.tools.keytool.Main')
        }
        catch (ClassNotFoundException e1) {
            try {
                // Sun pre-JDK 8
                return Class.forName('sun.security.tools.KeyTool')
            }
            catch (ClassNotFoundException e2) {
                 // no try/catch for this one, if neither is found let it fail
                 return Class.forName('com.ibm.crypto.tools.KeyTool')
            }
        }
    }
    catch (Throwable e) {
        return null
    }
}