001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.cli; 020 021import java.io.File; 022import java.io.FilenameFilter; 023import java.lang.reflect.Method; 024import java.net.URL; 025import java.net.URLClassLoader; 026 027public class MainEntryPoint { 028 029 public static void main(String[] args) throws Throwable { 030 File libDir=new File("./").getCanonicalFile(); 031 System.out.println(libDir); 032 033 // Fix for tomcat 034 if(libDir.getName().equals(".") || libDir.getName().equals("..")) 035 libDir=libDir.getParentFile(); 036 037 File[] children = libDir.listFiles(new ExtFilter()); 038 if(children.length<2) { 039 libDir=new File(libDir,"lib"); 040 children = libDir.listFiles(new ExtFilter()); 041 } 042 043 URL[] urls = new URL[children.length]; 044 System.out.println("Loading Jars"); 045 for(int i=0;i<children.length;i++){ 046 urls[i]=new URL ("jar:file://" + children[i] + "!/"); 047 System.out.println("- "+urls[i]); 048 } 049 System.out.println(); 050 URLClassLoader cl = new URLClassLoader(urls,ClassLoader.getSystemClassLoader()); 051 Class cli = cl.loadClass("lucee.cli.CLI"); 052 Method main = cli.getMethod("main",new Class[]{String[].class}); 053 main.invoke(null, new Object[]{args}); 054 055 056 } 057 058 059 public static class ExtFilter implements FilenameFilter { 060 061 private String ext=".jar"; 062 public boolean accept(File dir, String name) { 063 return name.toLowerCase().endsWith(ext); 064 } 065 066 } 067}