6

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.

V H
  • 8,382
  • 2
  • 28
  • 48
  • did you try\can you upgrade to grails 2.5.x? – shaydel Dec 08 '15 at 13:10
  • That was where I started. I hit this issue http://grails.1312388.n4.nabble.com/ANN-Grails-2-4-5-and-Grails-2-5-0-released-td4658938.html 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 Dec 08 '15 at 13:50

1 Answers1

6

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
    }
}
  • 1
    Thank you for this code snippet, which may provide some immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its educational value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Jun 21 '17 at 10:55
  • As a Grails-newbie it may be hard to know how to get your Tomcatserver-plugin to compile. I wrote a question (and answer, but there may be better ways) regarding this: https://stackoverflow.com/a/55142224/1037864 – Björn Mar 13 '19 at 12:56
  • 1
    @Björn Martin is talking about the source project of grails tomcat - https://github.com/grails-plugins/grails-tomcat-plugin/blob/ffc1a25f51a94731aaad30698b3e1e7be4f1ea3e/src/groovy/org/grails/plugins/tomcat/TomcatServer.groovy#L312-L327 - you would typically download the plugin and compile it within your project - https://stackoverflow.com/questions/8152183/how-to-run-a-local-plugin-in-grails-2-0 – V H Mar 13 '19 at 16:27
  • @Vahid Thanks! I'm going to try this and update my answer with my findings. – Björn Mar 14 '19 at 07:12
  • @Vahid do you have any pointers on how to compile the Tomcat plugin within my project? I pointed the Tomcat's plugin-location to the source code but with no luck. – Björn Mar 15 '19 at 09:27
  • 1
    @Björn there are a couple of choices - you will need to keep a local copy of that specific plugin - the simplest way is to have the amended plugin locally - and https://github.com/vahidhedayati/kchat/blob/master/grails-app/conf/BuildConfig.groovy#L83 add a local line then when you do grails war - it will package that local plugin with the war file for prod. if you have some automated process like jenkins that relies on remote building then u may need some local central repo to put plugin into https://computerramblings.wordpress.com/2014/01/08/adding-a-plugin-from-local-source-in-grails-2-3-2/ – V H Mar 15 '19 at 09:53