Deploying Java Servlet applications on Windows with IIS

Java platform is extremely successful in building robust and high performance web applications. Platform independence is one of the strength of Java engine and Helicon Zoo now provides a convenient way to deploy and run Java web applications on Windows platform with Microsoft IIS. To deploy Java Servlet application on IIS 7 you will only need to follow this simple instruction:

Platfrom installation

  1. Download and install Web Platform Installer.
  2. Run Web Platform Installer and click “Options”.
  3. Add Helicon Zoo feed into Display additional scenarios box:  http://www.helicontech.com/zoo/feed. New “Zoo” tab will appear.
  4. Go to the Zoo, Packages and install Java Hosting Package.
  5. Accept licenses to start installation process.

Alternatively, instead of installing Java Hosting Package you can install Modules –> Helicon Zoo Module and Engines –> Jetty separately. This is minimal requirement to run Java Servlet applications under Microsoft IIS web server. If you want to run Java Servlets under IIS Express and WebMatrix in your development environment, then you will also need to install Helicon Zoo Module for IIS Express form Engines section.

This is enough configuration to run most of Java Servlet applications directly form IIS.

Installing application

Launch IIS Manager and create new web-site or an application within a web-site. Copy your Java application into the root folder of this IIS application. Java application could be either a single .war file or set of unpacked files with directory structure, including web-inf folder. Then just create the following web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <heliconZoo>
      <application name="jetty.project" >
        <environmentVariables>
          <!-- Uncomment line below if you want to set contexts directory -->
          <!--  <add name="CONTEXTS_DIR" value="%APPL_VIRTUAL_PATH%" /> -->

          <!-- Optional variables: -->
          <!-- <add name="CONTEXT_PATH" value="%APPL_VIRTUAL_PATH%" /> -->
          <!-- <add name="WAR_EXTRACT_PATH" value="%APPL_PHYSICAL_PATH%" /> -->

          <!-- A WAR file or start directory to run -->
          <add name="WAR_FILE" value="my_application.war" />
        </environmentVariables>
        </application>
    </heliconZoo>

        <handlers>
          <add name="jetty.project#x86" scriptProcessor="java.jetty" 
            path="*" verb="*" modules="HeliconZoo_x86" 
            preCondition="bitness32" resourceType="Unspecified" 
            requireAccess="Script" />
          <add name="jetty.project#x64" scriptProcessor="java.jetty" 
            path="*" verb="*" modules="HeliconZoo_x64" 
            preCondition="bitness64" resourceType="Unspecified" 
            requireAccess="Script" />
        </handlers>
  </system.webServer>
</configuration>

Please take a look at <environmentVariables> section.

  • CONTEXTS_DIR — optional path to directory with .xml files which describe Jetty contexts. If this variable isn’t set, Zoo looks for “contexts” folder in the root of application. If no such folder found, Zoo presumes the application has single context and uses variables described below.
  • CONTEXT_PATH — optional virtual path of the application. Default value is taken from APPL_VIRTUAL_PATH variable.
  • WAR_FILE — optional path to a .war file or directory with extracted application.
  • WAR_EXTRACT_PATH — optional .war file extraction path. Is set to application’s root folder by default.

Here is an example of context.xml file that you may use instead of setting WAR file name explicitly. This allows to run multiple applications and contexts in a single IIS web site.

contexts/context.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

   <Set name="contextPath">/application</Set>
   <Set name="war">my_application.war</Set>
   <Set name="tempDirectory">application_dir</Set>

</Configure>

WARNING: Since WAR files need to be extracted before execution you will need to have a folder with write permissions.  In default IIS installation all application pools are executed with permissions of IIS_IUSRS group which does not have write permissions to the web application folders. You will need to provide write permissions to the user running Application Pool or IIS_IUSRS group to the folder containing Java application or specify other folder using WAR_EXTRACT_PATH variable with write permissions provided.

Now you can open IIS web site in the browser and see your Java web application running.

That’s it! Installation process is clear and automatic and will only take several minutes.

This entry was posted in Helicon Zoo and tagged . Bookmark the permalink.

5 Responses to Deploying Java Servlet applications on Windows with IIS

  1. Peter says:

    Downloaded and installed as described in the article (http://www.helicontech.com/articles/deploying-java-servlet-applications-on-windows-with-iis/).

    However for some weird reason I can successfully view the Java app via IIS when using http://localhost/appname but if I do the same thing http:///appname on another machine I get a a 404 from IIS and if I do it on the server itself I get a 404 from Jetty instead.

    This is running on a 64bit Win2008R2 Std server VM with an IIS app set up to use a ASP.NET 4.0 integrated app pool.
    The folder the IIS app points to contains the contents of the WAR file, i.e. \web-inf and \xforms-jsp and the web.config with the described contents from the article.

    Any ideas on what could be wrong would be much appreciated.

    • Slavik says:

      Hello.
      Please try and use CONTEXT_PATH variable as follows:
      <add name="CONTEXTS_PATH" value="/appname" />

      Make sure “appname” is an application. If it’s not, open IIS manager, navigate to that folder and in the context menu click “Convert to Application”.

  2. jules says:

    I installed on a Windows 7 64 bit machine and then downloaded the jenkins.war file and tried to deploy it:
    But I get:
    HTTP ERROR: 503
    Problem accessing /test. Reason:
    Service Unavailable
    Powered by Jetty://

    ??

    • Slov says:

      I think installing Jenkins on IIS may deserve a separate article.
      First you will need to upgrade your Jetty installation as we have fixed some functions. Just delete C:\jetty folder and install again using Helicon Zoo feed.
      Then you will need to use contexts folder, instead of setting WAR file explicitly as Jenkins require additional configurations.
      Please remove all “environmentVariables” from web.config, create contexts folder, and create context.xml file in this folder with the following content:

      < ?xml version="1.0"?>
      < !DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">





      Test Realm


      /jenkins
      jenkins.war

      After that navigate to http://localhost/jenkins (not to the root folder). It should work now.

      • Slov says:

        A bug with tags. Try again:

        <?xml version=”1.0″?>
        <!DOCTYPE Configure PUBLIC “-//Jetty//Configure//EN” “http://www.eclipse.org/jetty/configure.dtd”>

        <Configure class=”org.eclipse.jetty.webapp.WebAppContext”>
        <Get name=”securityHandler”>
        <Set name=”loginService”>
        <New class=”org.eclipse.jetty.security.HashLoginService”>
        <Set name=”name”>Test Realm</Set>
        </New>
        </Set>
        </Get>

        <Set name=”contextPath”>/jenkins</Set>
        <Set name=”war”>jenkins.war</Set>
        <Set name=”tempDirectory”>jenkins</Set>
        </Configure>