2012-11-05 101 views
1

我將Tomcat 7.0.32嵌入到Flume Source中。我遇到的問題是Flume在Classpath中放置了大量的東西,並且在啓動時,Tomcat掃描類路徑尋找TLD,這是由於flume使用的通配符而導致的問題。嵌入式Tomcat 7.0.32啓動jar掃描器

信息:啓動Servlet引擎:的Apache Tomcat/7.0.32 2012年11月5日上午08時21分08秒org.apache.catalina.startup.TldConfig tldScanJar 警告:無法處理JAR [JAR:文件:/ TLD文件的opt/mapr/hadoop/hadoop-0.20.2/hadoop * core * .jar!/] java.io.FileNotFoundException:/opt/mapr/hadoop/hadoop-0.20.2/hadoop*core*.jar (沒有這樣的文件或目錄) at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile。(ZipFile.java:214) at java.util.zip.ZipFile。( (JarFile.java:152) at java.util.jar.JarFile。(JarFile.java:89) at sun.net.www.protocol.JPG.JarFile.JarFile.java:144) at sun.www.protocol。 JA r.URLJarFile。(URLJarFile.java:93) at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69) at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory .java:88) at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122) at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:89) 在org.apache.tomcat.util.scan.FileUrlJar。(FileUrlJar.java:41) at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:34) at org.apache.catalina。 startup.TldConfig.tldScanJar(TldConfig.java:487) 在org.apache.catalina.startup.TldConfig.access $ 100(TldConfig.java:58) 在org.apache.catalina.startup.TldConfig $ TldJarScannerCallback.scan(TldConfig的.java:303 ) 在org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:241) 在org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:204) 在org.apache .catalina.startup.TldConfig.execute(TldConfig.java:277)

在我的代碼中,我試圖禁用這個掃描,甚至嘗試在我的上下文中將JarScanner設置爲null。這並沒有幫助。以下是我的代碼:

File docBase = new File(System.getProperty("java.io.tmpdir")); 
    System.out.println("------- " + docBase.getAbsolutePath()); 

    String servletName = "1 source"; 

    Tomcat tomcat = new Tomcat(); 
    tomcat.setPort(8080); 
    tomcat.setBaseDir(docBase.getAbsolutePath()); 

    Context context = tomcat.addContext("", docBase.getAbsolutePath()); 
    context.setIgnoreAnnotations(true); 
    context.setJarScanner(null); 

    Tomcat.addServlet(context, servletName, new HttpServlet() { 

回答

1

試試這個! 上下文context = tomcat.addWebapp(「/ d」,「d:/」); JarScanner jarScanner =新JarScanner() {

 @Override 
     public void scan(ServletContext arg0, ClassLoader arg1, 
       JarScannerCallback arg2, Set<String> arg3) 
     { 
      //do nothing 
     } 
    }; 
    context.setJarScanner(jarScanner); 
1

喲可以tomcat.addWebapp()之前禁用掃描類路徑和清單:

ContextConfig contextConfig = new ContextConfig() { 
      private boolean invoked = false; 

      @Override 
      public void lifecycleEvent(LifecycleEvent event) { 
       if (!invoked) { 
        StandardJarScanner scanner = new StandardJarScanner(); 
        scanner.setScanClassPath(false); 
        scanner.setScanManifest(false); 
        ((Context) event.getLifecycle()).setJarScanner(scanner); 
        invoked = true; 
       } 
       super.lifecycleEvent(event); 
      } 
     }; 
     Context ctx = tomcat.addWebapp(tomcat.getHost(), "/", "path/to/war", contextConfig);