Dashboard > Penrose 1.0 > ... > Penrose Server User Guide > Tomcat
Tomcat
Added by Endi S. Dewata, last edited by Endi S. Dewata on Nov 30, 2006  (view change)
Labels: 
(None)


Introduction

Starting from Penrose 1.1.3 you can embed Penrose Server inside Tomcat.

Tomcat Setup

The jmx.jar in TOMCAT_HOME/bin is old, replace it with the one in PENROSE_SERVER_HOME/lib.

Web Application Setup

To make Penrose available in your web application, copy all jar files from the following directories:

  • PENROSE_SERVER_HOME/lib
  • PENROSE_SERVER_HOME/lib/ext
  • PENROSE_SERVER_HOME/server/lib
  • PENROSE_SERVER_HOME/server/lib/ext
  • PENROSE_SERVER_HOME/schema/ext

into the WEB-INF/lib directory. Exception: do not copy jbossall-client.jar.

Then copy PENROSE_SERVER_HOME/conf/log4j.xml into WEB-INF/classes.

Example

See the sample files in PENROSE_SERVER_HOME/samples/tomcat.

In this example, we have a servlet that will initialize Penrose Server:

public class DemoServlet extends GenericServlet {

    PenroseServer penroseServer;

    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);

        try {
            String home = servletConfig.getInitParameter("penrose.home");

            System.out.println("Starting Penrose Server at "+home+"...");
            penroseServer = new PenroseServer(home);
            penroseServer.start();

            System.out.println("Penrose Server started.");

        } catch (Exception e) {
            System.out.println("Failed starting Penrose Server: "+e.getMessage());
            throw new ServletException(e);
        }

    }

    public void destroy() {
        try {
            System.out.println("Stopping Penrose Server...");
            penroseServer.stop();

            System.out.println("Penrose Server stopped.");

        } catch (Exception e) {
            System.out.println("Failed stopping Penrose Server: "+e.getMessage());
        }
    }
}

In the web.xml, the servlet is configured to start when the web application is started.

<web-app>

    <servlet>
        <servlet-name>DemoServlet</servlet-name>
        <servlet-class>org.safehaus.penrose.example.tomcat.DemoServlet</servlet-class>
        <init-param>
            <param-name>penrose.home</param-name>
            <param-value>${penrose.home}</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

</web-app>

Run "ant deploy" to deploy the web application into Tomcat.

Site running on a free Atlassian Confluence Open Source Project License granted to Safehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators