You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Hammes <Pa...@gmx.de> on 2007/06/27 16:04:54 UTC

unzip a jar file from a war file to tomcat/webapp

Hi,

i have to unzip a jar, contained in a war file. This jar file is contained in the web-inf/lib directory. There are several images in this jar and i want to unzip it to tomcat/webapp directory so the browser can access the images directly. The process of unzipping should be triggerd by the automatic deploy of the war file by tomcat.

How can I manage to do this?

Thanks

Paul
-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: unzip a jar file from a war file to tomcat/webapp

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paul,

Paul Hammes wrote:
> i have to unzip a jar, contained in a war file. This jar file is
> contained in the web-inf/lib directory. There are several images in
> this jar and i want to unzip it to tomcat/webapp directory so the
> browser can access the images directly. The process of unzipping
> should be triggered by the automatic deploy of the war file by tomcat.

I'm not sure if you can actually listen for "auto-deploy" events, but
you can certainly listen for an "app is ready" events by using a
ServletContextListener.

When the context is initialized, you can open your JAR file like this:

private static final String JAR = "/WEB-INF/lib/my.jar";

public void contextInitialized(ServletContextEvent evt)
{
    InputStream in = null;
    JarInputStream jin = null;

    try
    {
        evt.getServletContext().getResourceAsStream(JAR);

    	if(null != in)
    	{
            jin = new JarInputStream(in);

	    // Do whatever you need to do with your JAR file.
        }
        else
        {
            logger.warn("Can't open JAR file");
        }
    }
    finally
    {
        if(null != jin) try { jin.close(); jin = in = null; }
                        catch(IOException ioe) { logger.error(ioe); }
        if(null != in) try { in.close(); }
                       catch(IOException ioe) { logger.error(ioe); }
    }
}

Don't forget to close that JAR file, even if you have to use the
contextDestroyed if you need to hold the JAR file open for the life of
the context.

Just out of curiosity, why do you need to open your own JAR file?

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGgnGX9CaO5/Lv0PARAik+AJ9G0m+e1pw6Dem6AAXzRggvFVx0OwCgscQz
8CzqNlPbjoKZbpgft5i+pag=
=ECcl
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org