2017-06-23 40 views
0

我試圖在嵌入模式下啓動Jetty以部署war文件。我正在使用版本爲9.4.6的jetty lib無法在嵌入模式下啓動Jetty

我在Gradle中創建了以下用於啓動Jetty並部署Web應用程序的任務。

println 'Starting Jetty............' 
project.ext.server = new Server(); 
ServerConnector connector = new ServerConnector(project.ext.server); 
connector.setPort(jettyPort); 
project.ext.server.addConnector(connector); 

WebAppContext webapp = new WebAppContext() 
webapp.setContextPath('/') 
def warPath = 'build/libs/'; 
warPath += 'test-' + project.version + '.war'; 
println("Deploying WAR File : --> ${warPath}"); 
webapp.setWar(warPath) 

project.ext.server.setHandler(webapp); 
project.ext.server.start(); 
println 'Server started, waiting...' 
new StopMonitor(jettyStopPort, project.ext.server).start(); 
println 'Jetty started.' 

但上面的腳本將失敗,並從失敗腳本以下錯誤

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.session.SessionHandler

精確線

WebAppContext webapp = new WebAppContext() 

即使我保留此行作爲腳本中的一行並刪除一切,我得到同樣的錯誤。

有趣的是,它所抱怨的類出現在jar文件jetty-server中。用於使用碼頭庫的相同腳本8.1

注意:爲了使腳本能夠在jetty 9.4上運行,我必須使用ServerConnector類而不是在Jetty 9.4中刪除的BlockingConnectot,其餘腳本是相同的。

我不知道爲什麼這個失敗。

+0

語言是什麼呢? – ekaerovets

回答

0

您可能缺少必需的jar文件。

強烈建議您使用合適的構建工具,您可以從中選擇多種

下面是在示例項目的jar依賴列表(以樹的形式)...

https://github.com/jetty-project/embedded-servlet-3.1

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ embedded-servlet-3.1 --- 
[INFO] org.eclipse.jetty.demo:embedded-servlet-3.1:war:1-SNAPSHOT 
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile 
[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.4.6.v20170531:compile 
[INFO] | +- org.eclipse.jetty:jetty-xml:jar:9.4.6.v20170531:compile 
[INFO] | | \- org.eclipse.jetty:jetty-util:jar:9.4.6.v20170531:compile 
[INFO] | \- org.eclipse.jetty:jetty-servlet:jar:9.4.6.v20170531:compile 
[INFO] |  \- org.eclipse.jetty:jetty-security:jar:9.4.6.v20170531:compile 
[INFO] |  \- org.eclipse.jetty:jetty-server:jar:9.4.6.v20170531:compile 
[INFO] |   +- org.eclipse.jetty:jetty-http:jar:9.4.6.v20170531:compile 
[INFO] |   \- org.eclipse.jetty:jetty-io:jar:9.4.6.v20170531:compile 
[INFO] \- org.eclipse.jetty:jetty-annotations:jar:9.4.6.v20170531:compile 
[INFO] +- org.eclipse.jetty:jetty-plus:jar:9.4.6.v20170531:compile 
[INFO] | \- org.eclipse.jetty:jetty-jndi:jar:9.4.6.v20170531:compile 
[INFO] +- javax.annotation:javax.annotation-api:jar:1.2:compile 
[INFO] +- org.ow2.asm:asm:jar:5.1:compile 
[INFO] \- org.ow2.asm:asm-commons:jar:5.1:compile 
[INFO]  \- org.ow2.asm:asm-tree:jar:5.1:compile 
+0

謝謝,添加servlet-api作爲依賴解決了這個問題。儘管它已經作爲傳遞依賴存在,但它仍然不起作用。 –