aspose file tools*
The moose likes Servlets and the fly likes Create and Compile Java class on application startup via Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Create and Compile Java class on application startup via Servlet" Watch "Create and Compile Java class on application startup via Servlet" New topic
Author

Create and Compile Java class on application startup via Servlet

Sachin Deokar
Ranch Hand

Joined: May 09, 2008
Posts: 41
Hi,

I am working on restructuring and migrating an old J2EE app to our new unix environment(deployed in Weblogic server). As part of the ant build process we have a target that calls a GenerateDBMetadata.java file which creates a DBMetadata.java class by connecting to the database and getting a list of all procedures and storing them in a hashmap. This class is then compiled as part of the build process. I am trying to take this out of the build script and was wondering if i could call the class GenerateDBMetadata.java in a Servlet on application startup in weblogic server and then create and compile DBMetadata.java class. Will <load-on-startup> element in web.xml work for this requirement? I have never done this before and would greatly appreciate your inputs.

Thanks in advance for your help. Please accept my apologies if I have posted this in wrong forum.

Regards,
Sachin
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

firstly don't use load-on-startup for anything that isn't related to bootstrapping the SErvlet. If you want to do it then use a ContextListener instead
Secondly, if you load and store the values, why hardcode it? Sure it can be hardcoded in the generated file from the build script, but on startup you can create an instance of a class for managing this information and then read and populate the data.
No need for dynamically creating and loading a class at runtime.
Sachin Deokar
Ranch Hand

Joined: May 09, 2008
Posts: 41
If I populate the data as static members of the class on application startup, how do I make sure that the object stays alive as long as the application is up? Any kinda cache mechanism?

- Sachin

David O'Meara wrote:firstly don't use load-on-startup for anything that isn't related to bootstrapping the SErvlet. If you want to do it then use a ContextListener instead
Secondly, if you load and store the values, why hardcode it? Sure it can be hardcoded in the generated file from the build script, but on startup you can create an instance of a class for managing this information and then read and populate the data.
No need for dynamically creating and loading a class at runtime.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

Place it in application scope.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Don't get me started about those stupid light bulbs.
 
subject: Create and Compile Java class on application startup via Servlet