2011-08-27 2 views
2

Netbeans 7.0.1 및 JDK 1.7을 사용하여 Netbeans 플랫폼 응용 프로그램을 만들었습니다.System.setProperty를 사용하여 NetBeans 플랫폼 응용 프로그램에 Embedded Jetty Endpoint를 생성 할 때의 문제

Embedded Jetty 7.4.5 (웹 서비스와 서블릿으로 구성된)를 사용하여 일반 모듈에서 자체 웹 응용 프로그램을 구현하고 모든 Jetty jar 파일과 "jetty"파일을 포함하는 라이브러리 래퍼 모듈을 만들었습니다 -j2sehttpspi-7.4.5.v20110725.jar "를 사용하여 웹 서비스의 끝점을 게시 할 수 있어야했습니다. 웹 모듈은 Jetty 모듈에 종속됩니다.

내가 사용하는 코드는 이것이다 :

System.setProperty("com.sun.net.httpserver.HttpServerProvider", 
    "org.mortbay.jetty.j2sehttpspi.JettyHttpServerProvider"); 

server = new Server(); 
JettyHttpServerProvider.setServer(server); 

//We read the config file 
String[] configFiles = {"etc/jetty.xml"}; 
for(String configFile : configFiles) { 
    XmlConfiguration configuration = 
     new XmlConfiguration(new File(configFile).toURI().toURL()); 
    configuration.configure(server); 
} 

// Web Services 
QueryWeb qWS = new QueryWeb(); 
Endpoint.publish("http://0.0.0.0:" + 
    (server.getConnectors()[0].getPort()) + "/ws", qWS); 

// Servlets 
HandlerCollection hc = (HandlerCollection)server.getHandler(); 
ServletContextHandler sch = 
    new ServletContextHandler(ServletContextHandler.SESSIONS); 
sch.setContextPath("/web"); 
sch.addServlet(stream.class, "/stream"); 
// We add the servlet handler to the server's context handler collection 
// because it's the one used by the Web Service Endpoint 
ContextHandlerCollection chc = (ContextHandlerCollection)hc.getHandlers()[0]; 
chc.addHandler(sch); 

server.start(); 

나는 시도하고 응용 프로그램을 실행, 나는 "Endpoint.publish"호출 후 다음과 같은 오류 얻을 :

Exiting C:\Program Files (x86)\NetBeans 7.0\harness\run.xml. 
Exiting C:\Program Files (x86)\NetBeans 7.0\harness\run.xml. 
C:\Program Files (x86)\NetBeans 7.0\harness\suite.xml:500: 
    The following error occurred while executing this line: 
C:\Program Files (x86)\NetBeans 7.0\harness\run.xml:225: 
    The following error occurred while executing this line: 
C:\Program Files (x86)\NetBeans 7.0\harness\run.xml:193: 
    The application is already running within the test user directory. 
    You must shut it down before trying to run it again. 

로를 이해가가는 한, 시스템이 "org.mortbay.jetty.j2sehttpspi.JettyHttpServerProvider"클래스를 찾을 수 없기 때문에 이런 일이 발생합니다. 따라서 기본적으로 JDK에 포함 된 웹 서버가 기본값으로 설정되므로 동일한 포트 (이 경우에는 8081)에서 실행하려는 두 웹 서버 (Jetty 및 JDK)를 얻게되므로 충돌이 발생합니다.

이 문제를 해결할 수있는 유일한 방법은 JRE의 "lib/ext"폴더에 모든 Jetty jar 파일을 복사하는 것입니다 ("jetty-j2sehttpspi-7.4.5.v20110725.jar"만 복사하면됩니다). 오류는 발생하지만 서버는 시작되지 않습니다). 이 방법으로 시스템은 필요한 클래스와 모든 의존성을 찾을 수 있습니다.

NetBeans가 자체 클래스 경로 로더를 사용한다고해도 System.setProperty 메서드는 이것을 무시하고 표준 클래스 경로에 액세스하려고 시도하고 있으며 NetBeans 플랫폼 응용 프로그램은 실제로 사용자가 변경할 수 없기 때문에 클래스 패스를 직접 (NetBeans 플랫폼에 의해 모듈을 관리한다는 목적을 능가 할 것입니다.), 래퍼 모듈에 포함 된 라이브러리를 사용하는 방법을 알지 못합니다.

내가 발견 한 임시 해결책으로 응용 프로그램을 계속 개발할 수는 있지만 정직하게 JRE 폴더에 내용을 복사하는 것은 용인 할 수없는 해결책이며 결국 클라이언트 컴퓨터에서 배포 및 설치 문제가 발생할 것입니다 (이미 Mac에서 시도했습니다. OS 머신과 나는 심지어 JRE가 라이브러리를 보관하여 어디서 똑같은 더러운 트릭을 할 수 있는지조차 몰랐다.

따라서이 문제에 대한 해결책이 있는지 또는 어떤 일이 벌어지고 있는지, 그리고 내 프로젝트의 전체 아키텍처를 다시 만들지 않고도 문제를 해결할 수있는 방법에 대해 더 잘 설명해 줄 수 있는지 물어보고 싶습니다. 이 작은 불편 함을 제외하고는 정상적으로 작동합니다.)

미리 감사드립니다.

답변

관련 문제