views:

67

answers:

1

Do you guys have your own little framework for project startups ? I mean, every time one needs to do the same things at the beginning:


Context initialization - ideally after arguments are processed. Sometimes without interactive user input, sometimes with input reader. Sometimes we need to load properties, sometimes not. Then we need to get a class out of context and run its method. Programming....programming until writing shell script to place everything on classpath.


It's true that it differs according to the actual needs. But it seems to me, that I'm doing always almost the same, again and again from the scratch. Sometimes I realize that I'm postponing my work just because I don't want to do these annoying startups.


It would be great if there was some kind of universal Main class doing reflection to specified bean, context initialization, argument parsing, interactive user input reading and have the programmer do the important things...All setup might be done via spring configuration. I think I'll have to do it by myself.

I'd appreciate your ideas

EDIT: What I'll do: Some kind of startup class which will get user and developer arguments( path to spring context file, bean to setup with user arguments and bean to instantiate, supply with spring context and run). Lighweight api for argument parsing, maybe something for interactive user input which might be tough

+1  A: 

I use an abstract base class from which all of my command line utilities are launched. The initialization process has some basic startup lifecyel methods defined. I don't use command line arguments

public abstract class MyAppBase {
 public abstract String[] getSpringConfigResource();
 public void loadConsoleApplication() {
  try {
   preLoad();
   initializeSpring();
   loadConfiguration();
   loadDynamicComponents();
   postApplicationLoad();
  }
  catch (Exception ex) {
   handleStartupException("error initialzing application", ex);
  }
 }
 ...
}

Concrete subclasses look something like:

public class MyApp extends MyAppBase {
 public String[] getSpringConfigResource() {
  return new String[] { "someapp/appctx.xml", "util/appctx2.xml" }; 
 }

 protected void postApplicationLoad() {
  SomeServer server = springCtx.getBean("server");
  server.start();
 }

 public static void main(String args[]) {
  initLogging("com/me/myAppLog4j.xml", MyApp.class);    
  MyApp myApp = new MyApp ();
  myApp.loadConsoleApplication();
 }
}

For some reason none of my swing based non-interactive apps use command line arguments (args[]), since these tend to be services with installers and properties files.

Justin
That's a really good design for what I meant..this template method pattern. Thanks for sharing
lisak