Java Error 1723

Background & Problem:

Because I have a lot of Firefox plugins installed, Firefox became pretty slow, so I had some plugins disabled, under which a plugin for running applets. Yesterday, I came on some page that required applets, but the plugin was missing, so I let the browser install it automatically. After that, I was unable to start Java. Trying to reinstall or uninstall Java, gave the error 1723.

System specs:

-Windows 7 64 bit
-JDK 6.18 32 bit

Googled Solutions:

Using Google I found some proposed solutions:

  • http://www.javafixer.org/error-1723.php, doing the Regedit fix damaged the Windows Installer, and Windows Installer 5.0 (needed for Win7) cannot be download from the Microsoft site. So this solution didn’t work for me.
  • JavaRA: http://raproducts.org/. If you try this, don’t forget to run it under administrator. This solution didn’t work for me.
  • RegCleaning by using for example http://www.piriform.com/ccleaner. Also didn’t work.
  • Install Visual C++ 2005 Redistributable Package (x86). Didn’t work.
  • Windows Installer CleanUp Utility from the Microsoft site. Didn’t work.
  • Manually deleting JDK files. Didn’t work.

What did work for me:

On some forum (out of the many that discuss about this irritating error), I found someone that fixed it by removing all “jre” related from the registry. This did it for me 🙂 Open regedit, and search for “jre” and look for keys (directories) that contain “jre” values (fields) that are related to Java. Delete those keys.

After doing this, the JDK installer ran without problems, and without mentioning about existing installations.

Grails & Jetty with multiple contexts

A webapp usually contains both dynamic resources (scripts, config files, html files) and static resources (jpg, zip files, data etc). These resources can be deployed all together as one package, but when you have a lot of static resources, you usually want them to be seperate from the dynamic resources. Reasons might be that you have that much static resources that it will slow down deployment or testing when packaged as a single unit, or you might want static resources to be served by a seperate service to improve performance, or you might want them to be in seperate filesytem hierarchy because the static resources might also be needed outside the webapp. In this post I describe two methods to solve the problem of seperating dynamic from static resources when using Grails and Jetty.

The methods are tested using:

  • Grails 1.0.3
  • Jetty 6.1.4 (default Jetty for Grails 1.0.3)
  • Static Resources 0.5 plugin

Method 1: Static Resources plugin & symbolic links

The Grails Static-Resources plugin is designed to separate dynamic from static resources.

Install:

  1. open a cmd/shell prompt and go into the directory of your Grails webapp project. I will call this directory <myapp-grails-project-base>.
  2. type: grails install-plugin static-resources
    The plugin will now be installed for the current webapp only.

I’ll show by example how the Static-Resources plugin works. Suppose you have a website called example.com and a webapp called myapp, then the webapp is available at http://example.com:8080/myapp/. When you have the plugin installed, everything under the /static/ (filesystem directory) will be available under http://example.com:8088/ when run in dev environment. Notice that port 8088 is used instead of port 8080. The plugin does this by starting a NanoHTTPD, which is a lightweight single class Java HTTP server. The plugin calls this the resource server.
When you go to http://example.com:8088/, you will get a directory listing of all the files located in the static directory, so you can start using them and linking to them, but there is a better way (read on).

If you put a pdf file at <myapp-grails-project-base>/static/archive/catalog2005.pdf (filesystem) then it will be available automatically and directly at http://example.com:8088/archive/catalog2005.pdf in a dev env.
You can hardcode links to http://example.com:8080/archive/catalog2005.pdf manually in the view, but you can also use the plugins dedicated resourceLinkTo tag for this. For the pdf link, this tag is used as: <g:resourceLinkTo dir=”archive” file=”catalog2005.pdf”/>

When running in prod env instead of dev, the resourceLinkTo tag will link to the URI /resources/archive/catalog2005.pdf instead of http://example.com:8080/archive/catalog2005.pdf. And this time it won’t start a NanoHTTPD server, it only changes the link. So in a prod env, you have to map /resources/ to <myapp-grails-project-base>/static/ yourself, in whatever production HTTP server you are using. You could do this in Tomcat 6 by putting something like <Context docBase=” <myapp-grails-project-base>/static/” path=”/resources”/> in the host element of server.xml, or better, in context.xml.

If you don’t want your resources to be located in the <myapp-grails-project-base>/static/ directory, you can use symbolic links in the static directory, and map them to elsewhere. Note that symbolic links are not only available on POSIX systems (Linux etc), but also on Windows systems using special tools. (I’m not talking about Windows Shortcuts, but Windows symbolic links, hard links or junctions.)

Another way is to change the static directory location by modifying <myapp-grails-project-base>\plugins\static-resources-0.5\grails-app\services\ExternalResourceServerService.groovy.

Method 2: a second Jetty webapp context

The static resources method (described above) doesn’t have a complete built-in solution for a production environment; you have to make/map the /resources/ URI yourself.

If want you to use Jetty in both dev and prod env, or if you want to have a separate static resources directory without using the Static-Resources plugin, then read on:

1) Open %GRAILS_HOME%\scripts\RunApp.groovy
2) change

    target( configureHttpServer : &quot;Returns a jetty server configured with an HTTP connector&quot;) {
    def server = new Server()
    grailsServer = server
    def connectors = [new SelectChannelConnector()]
    connectors[0].setPort(serverPort)
    server.setConnectors( (Connector [])connectors )
    setupWebContext()
    server.setHandler( webContext )
    event(&quot;ConfigureJetty&quot;, [server])
    return server
}

to

    target( configureHttpServer : &quot;Returns a jetty server configured with an HTTP connector&quot;) {
    def server = new Server()
    grailsServer = server
    def connectors = [new SelectChannelConnector()]
    connectors[0].setPort(serverPort)
    server.setConnectors( (Connector [])connectors )
    setupWebContext()

    server.addHandler( webContext )
    WebAppContext resourceContext = new WebAppContext(&quot;D:/myapp-grails-project-base/static&quot;, &quot;/resources&quot;)
    server.addHandler(resourceContext);

    event(&quot;ConfigureJetty&quot;, [server])
    return server
}

Now, everything under D:/myapp-grails-project-base/static will be mapped to http://…../resources, in both dev and prod evironment, and will be served seperate from the webapp.

A drawback of placing this in RunApp.groovy is that every Grails app will have a /resources context running next to it.

Note that Jetty 5 and earlier versions of Grails probably needs different code.

Edit:
Grails maintains a temperary directory for scripts in %userhome%\.grails\1.0.3\scriptCache. I you find that modifications aren’t visible, then try deleting that directory.

More info: