Create and Compile Java class on application startup via Servlet
Sachin Deokar
Ranch Hand
Joined: May 09, 2008
Posts: 41
posted
0
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.
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
posted
0
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.