01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License. For additional information regarding
15: * copyright in this work, please see the NOTICE file in the top level
16: * directory of this distribution.
17: */
18: package org.apache.roller.business.runnable;
19:
20: import java.io.File;
21: import org.apache.roller.util.StandaloneWebappClassLoader;
22:
23: /**
24: * Sets up classpath for Roller and runs a task.
25: * Expects these JVM parameters:
26: * webapp.dir must specify Roller webapp directory
27: * jars.dir must specify additional jars directory (e.g. Tomcat commons/lib)
28: */
29: public class TaskRunner {
30:
31: public TaskRunner() {
32: }
33:
34: public static void main(String[] args) throws Exception {
35: if (args.length < 3) {
36: System.err
37: .println("USAGE: java -cp roller-planet.jar TaskRunner WEBAPPDIR JARSDIR CLASSNAME");
38: System.err
39: .println("WEBAPPDIR: The directory path to the web application ");
40: System.err
41: .println(" (e.g. $CATALINA_HOME/webapps/roller)");
42: System.err
43: .println("JARSDIR: The directory path to the additional jars ");
44: System.err
45: .println(" directory (e.g. $CATALINA_HOME/common/lib)");
46: System.err
47: .println("CLASSNAME: The name of the class to be executed by TaskRunner ");
48: System.exit(-1);
49: }
50: String webappDir = args[0];
51: String jarsDir = args[1];
52: String taskClassName = args[2];
53: System.out.println("WEBAPPDIR = " + webappDir);
54: System.out.println("JARSDIR = " + jarsDir);
55: System.out.println("CLASSNAME = " + taskClassName);
56:
57: File webappDirFile = new File(webappDir);
58: File jarsDirFile = new File(jarsDir);
59: if (!webappDirFile.isDirectory() || !jarsDirFile.isDirectory()) {
60: System.err
61: .println("ERROR: webapp.dir and jars.dir must specify existing directories");
62: System.exit(-1);
63: }
64:
65: ClassLoader cl = new StandaloneWebappClassLoader(webappDir,
66: jarsDir, null);
67:
68: // We're using the new classloader from here on out
69: Thread.currentThread().setContextClassLoader(cl);
70:
71: // Go!
72: Class taskClass = cl.loadClass(taskClassName);
73: Runnable task = (Runnable) taskClass.newInstance();
74: task.run();
75: }
76: }
77:
78: /* for example:
79:
80: java \
81: -Dplanet.custom.config=planet-custom.properties \
82: -Dcatalina.base=. \
83: -cp ./build/webapp/WEB-INF/lib/roller-business.jar \
84: org.apache.roller.business.runnable.TaskRunner \
85: ~/roller_trunk/sandbox/planetroller/build/webapp \
86: /Applications/Java/jakarta-tomcat-5.5.9/common/lib \
87: org.apache.roller.planet.tasks.GeneratePlanetTask
88:
89: */
|