On Thursday 13 November 2003 05:34 pm, eduard wrote:
> Nico Klasens wrote:
>
> >>Could as well make that implicit when using the
> >>'mmbase.config' property, because using it implies that
> >>you're problably trying to run mmbase outside a servlet environment.
> >>
> >>
> >
> >Hwat about appservers which don't unwar the WAR-file. The mmbase config
> >has to be on the file system. A -Dmmbase.config can fix this. It will
> >definitienly go wrong when Mmbase thinks it is running standalone.
> >
> >
> I dont think we can talk about a standalone mode, more of an check that
> MMBase will not be started by calling the MMCI
> If you would not load any servlets, and you try to access MMBase from
> within the jsp you will get the message: "mmbase has not been started,
> and cannot be started by this class". (could even be reported as an bug)
> If you still want to start MMBase you can put the do the following call
> previously: org.mmbase.module.core.MMBase.getMMBase(); (assumed that the
> mmbase.config is configured allright). This is also done in the servlets
> to get the system running. There is an check in the CloudContext which
> checks if MMBase is already running, and if not it will produce the
> error. I would like to see this changed in such a way that it will use
> start MMBase when it is not running.
Actualy i think it's a bit more complicated
you also need to start logging.
here is how i do it with java reflection
File configDir = new File(startDir, "WEB-INF/config");
System.setProperty("mmbase.config", configDir.getPath());
//start logging
Class clazz = c.loadClass("org.mmbase.util.logging.Logging");
Method method = clazz.getMethod("configure", new Class[] { String.class });
method.invoke(null, new Object[] { configDir.getPath() + "/log/log.xml" });
System.err.println(clazz.getName());
//init mmbase context
Class mmbaseContext = c.loadClass("org.mmbase.module.core.MMBaseContext");
Method mmbaseContext_init = mmbaseContext.getMethod("init", new Class[] {});
mmbaseContext_init.invoke(null, new Object[] {});
//get the mmbase module this should start mmbase
Class mmbase = c.loadClass("org.mmbase.module.core.MMBase");
Method mmbaseGetMMBase = mmbase.getMethod("getMMBase", new Class[] {});
mmbaseGetMMBase.invoke(null, new Object[] {});
//get the mmadmin module and way untill it's loaded
attached a "runner" that start mmbase command line (after loading required jars from
the subdirectories/*
This software is OSI Certified Open Source Software.
OSI Certified is a certification mark of the Open Source Initiative.
The license (Mozilla version 1.0) can be read at the MMBase site.
See http://www.MMBase.org/license
*/
import java.io.File;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;
/**
* @author Kees Jongenburger
**/
public class Runner {
String[] argv;
public Runner(String[] argv)
throws MalformedURLException, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
this.argv = argv;
//get the current directory
String currentDir = System.getProperty("user.dir");
File startDir = new File("/home/keesj/mmsite");
File configDir = new File(startDir, "WEB-INF/config");
System.setProperty("mmbase.config", configDir.getPath());
Hashtable requirement = new Hashtable();
List list = findJars(startDir);
URL[] urls = new URL[list.size()];
for (int x = 0; x < list.size(); x++) {
File file = (File)list.get(x);
urls[x] = file.toURL();
System.err.print("adding: " + urls[x] + "\r");
}
URLClassLoader c = new URLClassLoader(urls, getClass().getClassLoader());
requirement.put("javax.servlet.http.HttpServletRequest", "servlet.jar");
requirement.put("javax.xml.parsers.DocumentBuilder", "xml.jar");
boolean isMissingClasses = false;
for (Iterator iter = requirement.keySet().iterator(); iter.hasNext();) {
String key = (String)iter.next();
try {
c.loadClass(key);
} catch (ClassNotFoundException e) {
System.err.println("missing class " + key);
isMissingClasses = true;
}
}
if (isMissingClasses) {
System.exit(1);
}
//start logging
Class clazz = c.loadClass("org.mmbase.util.logging.Logging");
Method method = clazz.getMethod("configure", new Class[] { String.class });
method.invoke(null, new Object[] { configDir.getPath() + "/log/log.xml" });
System.err.println(clazz.getName());
//init mmbase context
Class mmbaseContext = c.loadClass("org.mmbase.module.core.MMBaseContext");
Method mmbaseContext_init = mmbaseContext.getMethod("init", new Class[] {});
mmbaseContext_init.invoke(null, new Object[] {});
//get the mmbase module this should start mmbase
Class mmbase = c.loadClass("org.mmbase.module.core.MMBase");
Method mmbaseGetMMBase = mmbase.getMethod("getMMBase", new Class[] {});
mmbaseGetMMBase.invoke(null, new Object[] {});
//get the mmadmin module and way untill it's loaded
}
List findJars(File directory) {
List list = new ArrayList();
if (directory.isDirectory()) {
File[] files = directory.listFiles();
for (int x = 0; x < files.length; x++) {
File file = files[x];
if (file.isDirectory()) {
list.addAll(findJars(file));
} else if (file.getName().endsWith(".jar")) {
list.add(file);
}
}
}
return list;
}
public static void main(String[] argv) throws Exception {
new Runner(argv);
}
}