This reminds me of a script I have written. It deletes the work directory for a given context and precompiles the JSPs. No need to fight with JSPC :-)

I have attached it, simple but effective.
Stephan



Amit Kirdatt wrote:

Different servlet containers have different ways of doing it, but the
following method is part of the spec:

http://<your-server-name>/MyPage.jsp?jsp_precompile

-----Original Message-----
From: Kamholz, Keith (corp-staff) USX [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 05, 2003 10:53 AM
To: 'Struts Users Mailing List'
Subject: RE: force precompilation of JSPs


Yes.


:-)


-----Original Message----- From: Ionel Gardais [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 05, 2003 2:48 AM To: Struts Users Mailing List Subject: force precompilation of JSPs


Hi,


I am experiencing a slow down when I access a JSP page for the first time after I deploy e web app.
Is there a way to force precompilation of these files as soon as the web app is deployed ?


Thanks,
ionel


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


This e-mail, including attachments, may include confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. If the reader of this e-mail is not the intended recipient or his or her authorized agent, the reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




package tools;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;

/**
   Deletes the "work" directory of the Tomcat for a given context and
   precompiles all provided JSPs. Note that the JSPs have to be provided
   in the (hardcoded) configuration file. <br />
   <b>Suggested usage:</b>
   <pre>
      try 
      {
         Precompiler pc = new Precompiler();
         File f = new File(pc.getProperty("workDir"));
         pc.delete(f);
         pc.precompile();
     } catch(Exception ex) { System.err.println("Error:" + ex);}   
   </pre>
   
   Configuration file:
   <pre>
   server=http://127.0.0.1:8080/shop8/
   workDir=c:/tomcat/work/Standalone/localhost/shop8
      
   u1=index.jsp   
   u2=view/Kunde.jsp   
   </pre>
   @version 1.0
   @author [EMAIL PROTECTED]
*/
public class Precompiler
{
   Properties props = new Properties();
   java.util.logging.Logger logger = LoggerInitiator.getLogger();
   
   public Precompiler() throws IOException
   {
      logger.info("Precompiler()");
      DataInputStream in = new DataInputStream( new BufferedInputStream( 
         new FileInputStream("resources/urls.properties")));
      props.load(in); 
   }
   
   
   public String getProperty(String value)
   {  return props.getProperty(value);   }
   
   
   /**
      recursively deletes all files (NOT! the directories) in the given
      directory.
   */
   public void delete(File dir) throws IOException
   {
      logger.info("Precompiler.delete()");      
      File[] files = dir.listFiles();
      logger.info("have " + files.length + " files");
      for(int i = 0; i < files.length; i++)
      {
         if (files[i].isDirectory())
         {
            delete(files[i]);
         }
         else
         {
            logger.info("Deleting:" + files[i].getAbsolutePath() + "=" 
            + files[i].delete());
         }
      }
   }
   
   
   
   /**
      Precompiles the provided JSPs. Call delete first, if you want ALL
      JSPs to be recompiled.
   */
   public void precompile() throws Exception
   {
      logger.info("Precompiler.precompile()");
      String server = props.getProperty("server");
      for(int i = 1; i < props.size() - 1; i++)
      {
         String jsp = server + props.getProperty("u" + i) + "?jsp_precompile";
         System.out.println("Loading:" + jsp);
         URL url = new URL(jsp);
         url.openConnection().getInputStream();    
      }
   }

   
   public static void main(String args[])
   {
      try 
      {
         Precompiler pc = new Precompiler();
         File f = new File(pc.getProperty("workDir"));
         pc.delete(f);
         pc.precompile();
     } catch(Exception ex) { System.err.println("Error:" + ex);}
      
   }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to