开发者

how to build a container kind of thing for executing my jobs

I want to develop a framework(eg automation) which people can use.The idea is i build a container kind of thing (eg tomcat but not exactly like a webserver).The container will have one xml file which will hold the enties of classes that are to be executed. (eg like web.xm开发者_C百科l of tomcat)

for eg xml (run.xml) can be like follows

<job>jobNameXyz</job>
<class>com.pkg.jobXyz <class>

Each of the xml job class should extedn MyBaseClass like how servlet extends HttpServlet and override specified method doJob

public class MyClass extends Job{

  public String doJob(){
   //do some thing
  }

}

When i place Myclass inside my continner and trigger container the jobmust run and the method doJob How can this be done?Any one can enter deploy his jobs by putting his class file in our dir and then editing run.xml How can this be done?Any guidelines


Your container should parse the XML file, extract a list of class names, call Class.forName for all the class names, to get a list of Class objects. Then use Class.newInstance to call the default constructor of each of the class, cast the created objects to Job, and call their doJob method.


I would use (and have been using) ANT for this purpose.

EDIT:

The couple of techniques that I have used are:

  1. Using ANT exec task
  2. Using customized ANT task.

Whichever technique you use, the idea is to call ANT to execute the build file. This can be invoked via invoking ANT process externally (using Runtime.exec java ant for instance) or invoking the build file programmatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜