📄 main.java
字号:
else if (condition.equals("property")) { String property=System.getProperty(st.nextToken()); eval=property!=null&&property.length()>0; } else if (condition.equals("java")) { String operator=st.nextToken(); String version=st.nextToken(); ver.parse(version); eval=(operator.equals("<")&&java_version.compare(ver)<0)||(operator.equals(">")&&java_version.compare(ver)>0) ||(operator.equals("<=")&&java_version.compare(ver)<=0)||(operator.equals("=<")&&java_version.compare(ver)<=0) ||(operator.equals("=>")&&java_version.compare(ver)>=0)||(operator.equals(">=")&&java_version.compare(ver)>=0) ||(operator.equals("==")&&java_version.compare(ver)==0)||(operator.equals("!=")&&java_version.compare(ver)!=0); } else if (condition.equals("nargs")) { String operator=st.nextToken(); int number=Integer.parseInt(st.nextToken()); eval=(operator.equals("<")&&nargs<number)||(operator.equals(">")&&nargs>number)||(operator.equals("<=")&&nargs<=number) ||(operator.equals("=<")&&nargs<=number)||(operator.equals("=>")&&nargs>=number)||(operator.equals(">=")&&nargs>=number) ||(operator.equals("==")&&nargs==number)||(operator.equals("!=")&&nargs!=number); } else { System.err.println("ERROR: Unknown condition: "+condition); eval=false; } expression&=not?!eval:eval; not=false; } String file=expand(subject).replace('/',File.separatorChar); if (_debug) System.err.println((expression?"T ":"F ")+line); if (!expression) { done.put(file,file); continue; } // Handle the subject if (subject.indexOf("=")>0) { int i=file.indexOf("="); String property=file.substring(0,i); String value=file.substring(i+1); if (_debug) System.err.println(" "+property+"="+value); System.setProperty(property,value); } else if (subject.endsWith("/*")) { // directory of JAR files - only add jars and zips // within the directory File dir=new File(file.substring(0,file.length()-1)); addJars(dir,done,false); } else if (subject.endsWith("/**")) { //directory hierarchy of jar files - recursively add all //jars and zips in the hierarchy File dir=new File(file.substring(0,file.length()-2)); addJars(dir,done,true); } else if (subject.endsWith("/")) { // class directory File cd=new File(file); String d=cd.getCanonicalPath(); if (!done.containsKey(d)) { done.put(d,d); boolean added=_classpath.addComponent(d); if (_debug) System.err.println((added?" CLASSPATH+=":" !")+d); } } else if (subject.toLowerCase().endsWith(".xml")) { // Config file File f=new File(file); if (f.exists()) _xml.add(f.getCanonicalPath()); if (_debug) System.err.println(" ARGS+="+f); } else if (subject.toLowerCase().endsWith(".class")) { // Class String cn=expand(subject.substring(0,subject.length()-6)); if (cn!=null&&cn.length()>0) { if (_debug) System.err.println(" CLASS="+cn); _classname=cn; } } else if (subject.toLowerCase().endsWith(".path")) { //classpath (jetty.class.path?) to add to runtime classpath String cn=expand(subject.substring(0,subject.length()-5)); if (cn!=null&&cn.length()>0) { if (_debug) System.err.println(" PATH="+cn); _classpath.addClasspath(cn); } } else { // single JAR file File f=new File(file); if(f.exists()) { String d=f.getCanonicalPath(); if (!done.containsKey(d)) { done.put(d,d); boolean added=_classpath.addComponent(d); if (!added) { added=_classpath.addClasspath(expand(subject)); if (_debug) System.err.println((added?" CLASSPATH+=":" !")+d); } else if (_debug) System.err.println((added?" CLASSPATH+=":" !")+d); } } } } catch (Exception e) { System.err.println("on line: '"+line+"'"); e.printStackTrace(); } } } /* ------------------------------------------------------------ */ public void start(String[] args) { ArrayList al=new ArrayList(); for (int i=0; i<args.length; i++) { if (args[i]==null) continue; else al.add(args[i]); } args=(String[])al.toArray(new String[al.size()]); // set up classpath: InputStream cpcfg=null; try { Monitor.monitor(); cpcfg=getClass().getClassLoader().getResourceAsStream(_config); if (_debug) System.err.println("config="+_config); if (cpcfg==null) cpcfg=new FileInputStream(_config); configure(cpcfg,args.length); File file=new File(System.getProperty("jetty.home")); String canonical=file.getCanonicalPath(); System.setProperty("jetty.home",canonical); } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { try { cpcfg.close(); } catch (Exception e) { e.printStackTrace(); } } // okay, classpath complete. System.setProperty("java.class.path",_classpath.toString()); ClassLoader cl=_classpath.getClassLoader(); if (_debug) { System.err.println("java.class.path="+System.getProperty("java.class.path")); System.err.println("jetty.home="+System.getProperty("jetty.home")); System.err.println("java.io.tmpdir="+System.getProperty("java.io.tmpdir")); System.err.println("java.class.path="+_classpath); System.err.println("classloader="+cl); System.err.println("classloader.parent="+cl.getParent()); } // Invoke main(args) using new classloader. Thread.currentThread().setContextClassLoader(cl); // re-eval the policy now that env is set try { Policy policy=Policy.getPolicy(); if (policy!=null) policy.refresh(); } catch (Exception e) { e.printStackTrace(); } try { for (int i=0; i<args.length; i++) { if (args[i]==null) continue; _xml.add(args[i]); } args=(String[])_xml.toArray(args); //check for override of start class String mainClass=System.getProperty("jetty.server"); if (mainClass!=null) _classname=mainClass; mainClass=System.getProperty("main.class"); if (mainClass!=null) _classname=mainClass; if (_debug) System.err.println("main.class="+_classname); invokeMain(cl,_classname,args); } catch (Exception e) { e.printStackTrace(); } } /** * Stop a running jetty instance. */ public void stop() { int _port=Integer.getInteger("STOP.PORT",-1).intValue(); String _key=System.getProperty("STOP.KEY",null); try { if (_port<=0) System.err.println("STOP.PORT system property must be specified"); if (_key==null) { _key=""; System.err.println("STOP.KEY system property must be specified"); System.err.println("Using empty key"); } Socket s=new Socket(InetAddress.getByName("127.0.0.1"),_port); OutputStream out=s.getOutputStream(); out.write((_key+"\r\nstop\r\n").getBytes()); out.flush(); s.close(); } catch (ConnectException e) { System.err.println("ERROR: Not running!"); } catch (Exception e) { e.printStackTrace(); } } private void addJars(File dir, Hashtable table, boolean recurse) throws IOException { File[] entries=dir.listFiles(); for (int i=0; entries!=null&&i<entries.length; i++) { File entry=entries[i]; if (entry.isDirectory()&&recurse) addJars(entry,table,recurse); else { String name=entry.getName().toLowerCase(); if (name.endsWith(".jar")||name.endsWith(".zip")) { String jar=entry.getCanonicalPath(); if (!table.containsKey(jar)) { table.put(jar,jar); boolean added=_classpath.addComponent(jar); if (_debug) System.err.println((added?" CLASSPATH+=":" !")+jar); } } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -