views:

186

answers:

1

I'm trying to display a Java applet in a page on a Grails server. I'm using Sun's handy Javascript snippet for displaying applets:

<script src="http://java.com/js/deployJava.js"&gt;&lt;/script&gt;
<script>
deployJava.runApplet({codeBase:"${createLinkTo(dir:'applet', absolute:'true')}",
    archive:"${createLinkTo(dir:'com/steve/applet', file='applet.jar', absolute:'true')}",
    code:"com.steve.Applet.class",
    width:"500", height:"500"}, null, "1.5");
</script>

In Config.groovy, I set up the different serverURLs:

environments {
    production {
        grails.serverURL = "http://10.0.xx.xxx/"
    }
    development {
        grails.serverURL = "http://10.0.yy.yyy:8080/"
    }
}

However, the links created by createLinkTo() all have "http://localhost:8080" instead of the URL I specified. (i.e. they look like "http://localhost:8080/my-app/applet".) Is this a bug? Is there a workaround?

A: 

I found a workaround. Instead of using createLinkTo, I just defined a new variable in Config.groovy:

environments {
    development {
        grails.appURL = "http://10.0.xx.xxx:8080/my-app"
    }   
    production {
        grails.appURL = "http://10.0.yy.yyy"
    }
}

In my code, I do this: import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH

//...
def appURL = CH.config.grails.appURL
//...

This at least lets me get a predictable path.

Steve Johnson