2014-09-30 1 views
3

webapps를 가장 많이 사용하는 jetty 서버가 내장되어 있습니다. 다른 전쟁을 전개 할 때 webappcontext를 구성하기 위해 디렉토리에 deployment descriptor.xml을 추가합니다. 나는 핫 전개 된 클래스 경로 (/ extJars)에 다른 위치에 빌드 된 jar 디렉토리를 추가하고 싶다. webapp descriptor.xml 내에서이 작업을 수행하는 방법을 보았습니다.이 작업은 개별 항아리를 사용하여 수행 할 수 있습니다. 그러나이 디렉토리의 모든 항아리를 읽으려고 여러 구성을 시도했지만 아무것도 작동하지 않았습니다. 여기에 내 otherWebApp.xml이 있습니다. 작동하는 구성으로 호출하고, 작동하지 않는 구성은 주석으로 처리합니다. 감사.WebAppContext extraClasspath를 통한 많은 jar 관리

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> 
    <Configure class="org.eclipse.jetty.webapp.WebAppContext"> 
     <Set name="war"><SystemProperty name="JETTY_HOME" default="." />/extApps/otherWebApp.war</Set> 
     <Set name="contextPath">/otherWebApp</Set> 
     <Set name="tempDirectory" ><SystemProperty name="JETTY_HOME" />/jetty/webapps/otherWebApp</Set> 
<Set name="extraClasspath"><SystemProperty name="JETTY_HOME" />/extJars/cadi-core-1.0.12.jar,<SystemProperty name="JETTY_HOME" />/extJars/cadi-aaf-1.0.12.jar,<SystemProperty name="JETTY_HOME" />/extJars/GLCookieDecryption-1.0.jar,<SystemProperty name="JETTY_HOME" />/extJars/rosetta-1.1.1.jar,<SystemProperty name="AJSC_HOME" />/extJars/env-1.4.2.jar,<SystemProperty name="JETTY_HOME" />/extJars/dme2-2.5.22.jar</Set> 
<!-- <Set name="extraClasspath"><SystemProperty name="JETTY_HOME" />/extJars/</Set> 
    </Configure> doesn't work --> 
<!-- <Set name="extraClasspath"><SystemProperty name="JETTY_HOME" />/extJars/*</Set> 
    </Configure> doesn't work --> 
<!-- <Set name="extraClasspath"><SystemProperty name="JETTY_HOME" />/extJars/*.jar</Set> 
    </Configure> doesn't work --> 
<!-- <Set name="extraClasspath"><SystemProperty name="JETTY_HOME" />/extJars</Set> 
    </Configure> doesn't work --> 
+0

웹 응용 프로그램을 서버의 처리기로 추가하기 전에 Java 코드에서 'WebAppContext'를 사용합니까? 또는 당신은'DeploymentManager'에 의지 할 것인가? –

+0

이'extraClasspath' jar 파일은 임베디드 서버의 모든'WebAppContext' 파일에 추가 되었습니까? 또는 단지 특정 것들? –

+0

배치 관리자를 사용하여 핫 배치 가능 폴더 위치를 작성 중입니다. 그런 다음 otherWebApp.war 및 otherWebApp를 추가하고 있습니다.xml을 폴더에 저장하고 배포 관리자가 XML 기반의 전쟁을 핫 전개합니다. 엄밀히 말하자면, 이러한 여분의 jar는 메인 webapp 용 클래스 로더에 의해 추가되지만,이 jar는 otherWebApp에서도 사용해야합니다. 전체적인 디자인/워크 플로우는 기본 webAppContext와 최신 배포 폴더를 모두 배포하는 배포 관리자를 설정하는 기본 jetty.xml을 가지고 있다고 생각합니다. 간단히 말해 모든 extJars가 xml을 사용하는 otherWebApp 클래스 경로에 있어야합니다. – user2116247

답변

2

3 가지 선택 사항이 있습니다.

1 : 내장에서

사용 부모 로더 우선 순위, 부모 로더 우선 순위를 사용하도록 WebAppContext을 말한다. (이것은 웹 애플리케이션 클래스를 통해 서버 클래스를 선호합니다)

<Configure class="org.eclipse.jetty.webapp.WebAppContext"> 
    <Set name="contextPath">/example</Set> 
    <Set name="war">example.war</Set> 
    <Set name="parentLoaderPriority">true</Set> 
</Configure> 

이 서버 클래스는 정보의 캐싱 (많은 도서관에서 일반적인 기술)을 수행하는 경우 그 캐시가 모든 웹 어플리케이션에 사용할 수 있습니다하는 부작용을 가지고 .

2 : 각 WebAppContext가 구성 할 수있는 WebAppClassloader 사용을 사용하여 사용자 정의 DeploymentManager가 WebAppClassloader

관리를위한 바인딩 : 서버 클래스 로더에서

  1. 노출 특정 클래스를
  2. 은 무엇 WebAppContext 구축 webapp와 서버 사이에 충돌이있는 경우 수행됩니다.

DeploymentManager을 사용하고 있으므로 바인딩 기술을 통해 표준화 할 수 있습니다. ExposeServerCommonBinding.java

package jetty; 

import org.eclipse.jetty.deploy.App; 
import org.eclipse.jetty.deploy.AppLifeCycle; 
import org.eclipse.jetty.deploy.graph.Node; 
import org.eclipse.jetty.server.handler.ContextHandler; 
import org.eclipse.jetty.webapp.WebAppContext; 

public class ExposeServerCommonBinding implements AppLifeCycle.Binding 
{ 
    public String[] getBindingTargets() 
    { 
     return new String[] 
     { "deploying" }; 
    } 

    public void processBinding(Node node, App app) throws Exception 
    { 
     ContextHandler handler = app.getContextHandler(); 
     if (handler == null) 
     { 
      throw new NullPointerException("No Handler created for App: " + app); 
     } 

     if (handler instanceof WebAppContext) 
     { 
      WebAppContext webapp = (WebAppContext)handler; 

      // System classes (or namespaces) present in server classloader to expose to webapp 
      webapp.addSystemClass("org.apache.log4j."); 
      webapp.addSystemClass("org.slf4j."); 
      webapp.addSystemClass("org.apache.commons.logging."); 

      // Server classes that cannot be overridden by webapp 
      webapp.addServerClass("-org.apache.log4j."); 
      webapp.addServerClass("-org.slf4j."); 
      webapp.addServerClass("-org.apache.commons.logging."); 
     } 
    } 
} 

을 그리고

DeploymentManager mgr = new DeploymentManager(); 

WebAppProvider provider = new WebAppProvider(); 
provider.setMonitoredDirResource(Resource.newResource(new File("./webapps/"))); 
mgr.addAppProvider(provider); 

mgr.addLifeCycleBinding(new ExposeServerCommonBinding()); 

이 기술은 동일하게 당신이이 규칙을 적용 할 수는 DeploymentManager를 통해 배포되는 모든 WebAppContexts에 적용됩니다를 사용하는 방법 :

자체를 바인딩 모든 웹 응용 프로그램.

3 : 웹 애플리케이션 배포 할 때 사용 사용자 정의 DeploymentManager 여기 extraClasspath

관리를위한 바인딩하는 것은 당신이 사전 빌드 서버 측에서 extraClasspath, 그리고에 사용할 수있는 또 다른 바인딩 대안의 자동이 extraClasspath 추가 웹 애플리케이션에

package jetty; 

import java.io.File; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.Locale; 

import org.eclipse.jetty.deploy.App; 
import org.eclipse.jetty.deploy.AppLifeCycle; 
import org.eclipse.jetty.deploy.graph.Node; 
import org.eclipse.jetty.server.handler.ContextHandler; 
import org.eclipse.jetty.webapp.WebAppContext; 

public class CommonExtraClasspathBinding implements AppLifeCycle.Binding 
{ 
    private List<File> extraClasspath = new ArrayList<>(); 

    public String[] getBindingTargets() 
    { 
     return new String[] { "deploying" }; 
    } 

    public void addAllJars(File dir) 
    { 
     for (File file : dir.listFiles()) 
     { 
      if (!file.isFile()) 
      { 
       continue; 
      } 
      if (file.getName().toLowerCase(Locale.ENGLISH).equals(".jar")) 
      { 
       addJar(file); 
      } 
     } 
    } 

    public void addJar(File jar) 
    { 
     if (jar.exists() && jar.isFile()) 
     { 
      extraClasspath.add(jar); 
     } 
    } 

    public void processBinding(Node node, App app) throws Exception 
    { 
     ContextHandler handler = app.getContextHandler(); 
     if (handler == null) 
     { 
      throw new NullPointerException("No Handler created for App: " + app); 
     } 

     if (handler instanceof WebAppContext) 
     { 
      WebAppContext webapp = (WebAppContext)handler; 

      StringBuilder xtraCp = new StringBuilder(); 
      boolean delim = false; 
      for (File cp : extraClasspath) 
      { 
       if (delim) 
       { 
        xtraCp.append(File.pathSeparatorChar); 
       } 
       xtraCp.append(cp.getAbsolutePath()); 
       delim = true; 
      } 

      webapp.setExtraClasspath(xtraCp.toString()); 
     } 
    } 
}