0
votes

I am trying to start Jetty in embedded mode to deploy a war file. I am using jetty lib versioned 9.4.6

I have following task created in Gradle for starting Jetty and deploying the web application.

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.'

but above script fails with following error

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

Exact line from the script which is failing is

WebAppContext webapp = new WebAppContext()

Even if I keep this line as the single line in the script and remove everything, I get the same error.

Interestingly, the class for which it is complaining is present in the jar file jetty-server. Same script used to work with jetty libs 8.1

Note: In order to make the script work with jetty 9.4, i had to use ServerConnector class instead of BlockingConnectot, which was removed in jetty 9.4, rest of the script is same.

I am not sure why this failing.

1
what language is this?ekaerovets

1 Answers

0
votes

You are probably missing required jar files.

Would strongly encourage you to use a proper build tool, you have many to choose from.

Here's the jar dependency list (in tree form) for the example project at...

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