1 package org.ibex.jinetd;
2 import org.ibex.util.*;
6 import java.util.zip.*;
10 public static String ROOT;
11 public static String LOGFILE;
12 public static PrintStream LOGSTREAM;
14 private static void configureRoot() throws Exception {
15 ROOT = System.getProperty("jinetd.root", null);
17 ROOT = autoDetectRoot();
18 System.setProperty("jinetd.root", ROOT);
22 private static void configureLogging() throws Exception {
23 LOGFILE = System.getProperty("jinetd.logfile", ROOT + File.separatorChar+"log.txt");
24 LOGSTREAM = new PrintStream(new FileOutputStream(LOGFILE, true));
25 System.setErr(LOGSTREAM);
26 System.setOut(LOGSTREAM);
29 private static String autoDetectRoot() throws Exception {
30 if (!(Main.class.getClassLoader() instanceof URLClassLoader))
31 throw new Error("unable to detect jinetd.root because my ClassLoader is not an instanceof URLClassLoader");
32 URL[] urls = ((URLClassLoader)Main.class.getClassLoader()).getURLs();
33 for(int i=0; i<urls.length; i++) {
34 if (!urls[i].getProtocol().equals("file")) continue;
35 File file = new File(urls[i].getPath());
36 if (file.isDirectory()) {
37 if (new File(file.getAbsolutePath() +
39 Main.class.getName().replace('.', File.separatorChar)+".class").exists())
40 return file.getAbsolutePath();
41 } else if (file.getAbsolutePath().endsWith(".jar")) {
42 ZipFile zf = new ZipFile(file);
43 if (zf.getEntry(Main.class.getName().replace('.', File.separatorChar)+".class") != null)
44 return new File(file.getParent()).getAbsolutePath();
47 throw new Error("unable to detect jinetd.root because " +
48 Main.class.getName() +
49 " was not in any of the ClassLoader URLs");
56 } catch (Throwable e) {
61 public static void main(String[] s) throws Exception {
63 Root root = new Root(Root.root);
66 if (root != null) root.scan();
67 } catch (Exception e) { Log.error(Main.class, e); }