Using Jetty to launch a Spring Boot application

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Jetty to launch a Spring Boot application

Robert Stroud
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Using Jetty to launch a Spring Boot application

Joakim Erdfelt-8
A directory listing is likely due to nothing handling the default url-pattern "/" and the DefaultServlet kicking in and showing the directory listing (as that's how your DefaultServlet is configured).

Also, what does this do?

server.addLifeCycleListener(this);

What does 'this' do with the lifecycle?
It could be the one creating/managing things for Spring (an unusual, but doable, technique).


Joakim Erdfelt / [hidden email]

On Tue, Jan 9, 2018 at 8:23 AM, Robert Stroud <[hidden email]> wrote:
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Using Jetty to launch a Spring Boot application

Jan Bartel
In reply to this post by Robert Stroud
Robert,

You don't say what version of jetty you are porting from?

If you're using spring web libraries, then you will need to ensure that you have annotation processing turned on. See this chapter of the jetty docs: https://www.eclipse.org/jetty/documentation/9.4.8.v20171121/annotations.html

Jan

On 9 January 2018 at 15:23, Robert Stroud <[hidden email]> wrote:
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <[hidden email]>
www.webtide.com
Expert assistance from the creators of Jetty and CometD


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Using Jetty to launch a Spring Boot application

Robert Stroud
In reply to this post by Joakim Erdfelt-8
Hi Joakim,

Thanks for your reply...
 
On 9 Jan 2018, at 15:18, Joakim Erdfelt <[hidden email]> wrote:

A directory listing is likely due to nothing handling the default url-pattern "/" and the DefaultServlet kicking in and showing the directory listing (as that's how your DefaultServlet is configured).

The default url-pattern “/“ is supposed to be handled by my application, so I wouldn’t expect it to be picked up by the DefaultServlet. Do I need to do something to turn off the DefaultServlet?

Also, what does this do?

server.addLifeCycleListener(this);

What does 'this' do with the lifecycle?

Ah - sorry. This is just an artefact of how the application is organised. The method to launch Jetty appears in a class that implements LifeCycle.Listener.

It could be the one creating/managing things for Spring (an unusual, but doable, technique).

I don’t think so - I think this is just a convenient way to avoid defining a separate class for the LifeCycle.Listener. 

The various Listener methods are simply used to update the GUI.

Best wishes,

Robert



Joakim Erdfelt / [hidden email]

On Tue, Jan 9, 2018 at 8:23 AM, Robert Stroud <[hidden email]> wrote:
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Using Jetty to launch a Spring Boot application

Robert Stroud
In reply to this post by Jan Bartel
Hi Jan,

Thanks for your reply…

On 9 Jan 2018, at 15:19, Jan Bartel <[hidden email]> wrote:

Robert,

You don't say what version of jetty you are porting from?

Quite an old version - Jetty 7.0.1. 

If you're using spring web libraries, then you will need to ensure that you have annotation processing turned on. See this chapter of the jetty docs: https://www.eclipse.org/jetty/documentation/9.4.8.v20171121/annotations.html

Aha - thank you. That will certainly be part of my problem…

I’ll let you know how I get on.

Best wishes,

Robert


Jan

On 9 January 2018 at 15:23, Robert Stroud <[hidden email]> wrote:
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <[hidden email]>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Using Jetty to launch a Spring Boot application

Joakim Erdfelt-8
Jetty 7 is Servlet 2.5

It's unlikely that you were using Servlet Annotations with your codebase, as those were added in Servlet 3.0.

Unless you recently added the annotations?


Joakim Erdfelt / [hidden email]

On Tue, Jan 9, 2018 at 9:30 AM, Robert Stroud <[hidden email]> wrote:
Hi Jan,

Thanks for your reply…

On 9 Jan 2018, at 15:19, Jan Bartel <[hidden email]> wrote:

Robert,

You don't say what version of jetty you are porting from?

Quite an old version - Jetty 7.0.1. 

If you're using spring web libraries, then you will need to ensure that you have annotation processing turned on. See this chapter of the jetty docs: https://www.eclipse.org/jetty/documentation/9.4.8.v20171121/annotations.html

Aha - thank you. That will certainly be part of my problem…

I’ll let you know how I get on.

Best wishes,

Robert


Jan

On 9 January 2018 at 15:23, Robert Stroud <[hidden email]> wrote:
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <[hidden email]>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Using Jetty to launch a Spring Boot application

Robert Stroud

On 9 Jan 2018, at 15:33, Joakim Erdfelt <[hidden email]> wrote:

Jetty 7 is Servlet 2.5

Thanks - yes, I know. The old version of the web application was built using an older version of Grails that didn’t use Spring Boot - the WAR file contained a conventional web.xml and it all worked fine.

It's unlikely that you were using Servlet Annotations with your codebase, as those were added in Servlet 3.0.

Indeed - the old version of the web application didn’t rely on Servlet annotations and worked with Servlet 2.5. I knew that the new version needed Servlet 3.0 but I hadn’t realised that I would need to enable annotation processing in order for Jetty to launch the new version of the web application correctly...

Unless you recently added the annotations?

No - but I’m adding them now, which will hopefully fix the problem.

Thanks for your help - much appreciated.

Best wishes,

Robert

Joakim Erdfelt / [hidden email]

On Tue, Jan 9, 2018 at 9:30 AM, Robert Stroud <[hidden email]> wrote:
Hi Jan,

Thanks for your reply…

On 9 Jan 2018, at 15:19, Jan Bartel <[hidden email]> wrote:

Robert,

You don't say what version of jetty you are porting from?

Quite an old version - Jetty 7.0.1. 

If you're using spring web libraries, then you will need to ensure that you have annotation processing turned on. See this chapter of the jetty docs: https://www.eclipse.org/jetty/documentation/9.4.8.v20171121/annotations.html

Aha - thank you. That will certainly be part of my problem…

I’ll let you know how I get on.

Best wishes,

Robert


Jan

On 9 January 2018 at 15:23, Robert Stroud <[hidden email]> wrote:
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <[hidden email]>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Using Jetty to launch a Spring Boot application

Robert Stroud
In reply to this post by Robert Stroud

On 9 Jan 2018, at 15:30, Robert Stroud <[hidden email]> wrote:

On 9 Jan 2018, at 15:19, Jan Bartel <[hidden email]> wrote:

If you're using spring web libraries, then you will need to ensure that you have annotation processing turned on. See this chapter of the jetty docs: https://www.eclipse.org/jetty/documentation/9.4.8.v20171121/annotations.html

Aha - thank you. That will certainly be part of my problem…

I’ll let you know how I get on.

Jan, Joakim,

Thank you so much for your help and your quick response - turning on annotation processing fixed the problem. 

For the benefit of anyone with a similar problem in the future, I simply needed to add two lines to my launch method, namely:
// Enable annotation processing so that Spring Boot does its magic
Configuration.ClassList classlist = Configuration.ClassList
.setServerDefault(server);
classlist.addBefore(
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration");

The example given in the Annotations chapter is more complicated because it configures JNDI as well, but for Spring Boot, you only need AnnotationConfiguration.

Best wishes,

Robert



Best wishes,

Robert


Jan

On 9 January 2018 at 15:23, Robert Stroud <[hidden email]> wrote:
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <[hidden email]>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users