Jetty Setup Walkthrough - Happy Coding

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there happy coders this is kevin from happy coding here and today i'm going to walk through the process of downloading and installing jetty and then using jetty to run a server on your local computer and deploy a hello world web application or website so jeti is is handy if you are getting into server-side coding because it lets you run a server on your own computer without worrying about figuring out how to run a live server or paying for a service that does that for you like google cloud or amazon web services or things like that so jeti is is nice for for getting into coding without needing to do any of that stuff so you can run through this on happycoding.io if you are if you prefer reading through tutorials but i'm just going to kind of run through it myself here so the first thing i want to do is download jetty so i'm going to just google jetty and i might have to google like jetty server i don't want this kind of jetty i want this kind of jetty right and i can go to download and i'm looking for the latest version which currently is 11. so i'm going to download this zip and that will download as a zip file which is just a file that contains a directory it's kind of an easier way to to package up multiple files without having to download a bunch of files um it's going to take a minute to download and while i stall for time we're just kind of waiting for this to finish maybe i should have done cooking show style where i just switch over to it already downloaded but whatever we're here together one thing i might talk about while it's finishing up whatever it's doing is that the different versions of jetty are quite a bit different so starting with i don't know if it was 10 or 11 they changed how some of it worked so um some of the stuff we're going to do today is different than what you would have had to do if you were using an old version anyway that that finished so i'm going to open up my zip file which gives me a directory and i'm going to unzip that directory you can put it anywhere you want i'm going to put it on my desktop for now and again maybe i should have done some this ahead of time but i wanted to sort of show every little step because i i feel like i always get stuck on some of this uh like set up stuff which is not super interesting but you know you just got to get through it to get to the fun stuff so i'm kind of demoing that kind of boring and painful process so whatever [Music] so i have this jetty home directory and it's jetty home dash 11.0.6 here because that's the current version and inside of it you've got a few uh directories and files and we'll get to them in a second but what i was talking about earlier where something changed in the more recent versions of jetty is that you'd no longer put your code in this directory in old versions you would put the code in this directory and in tomcat if you've watched that video tomcat servers you also put your code directly inside of the kind of the download folder both jetty at least the latest version is a little different so um what you actually need to do is create a new directory and we're going to call it like jetty bass you know you can actually call it whatever you want but jetty calls it jetty bass internally so i'm going to stick with that so now i've got my jetty home which contains jetty itself and i've got my jetty base directory which actually doesn't contain anything yet and that's okay so the next thing that i want to do is kind of initialize jetty so i have these files downloaded and i have my empty directory but i need to kind of connect these two directories i need to tell jetty that this is a sort of jetty web app directory and there are a few ways to do that and both ways kind of have one thing in common where you need to run this uh wait this one of these let's see um it is in oh it's just in the top level directory oh it's right here duh so you have to run this jar file and point it to your jetty base directory and so you can either open a command line to jetty base and run your command there pointing it to the jar or you can do it the other way around and run this jar from this directory pointing it to jettybase and so for fun maybe i'll just do both i don't know how fun that's going to be but just to demonstrate both so i'm in jetty home and so what i need to do is run start.jar which is in this directory and point it to jetty base so the way i would do that is i'm going to run java dash jar and then i'm going to give it the start.jar file name and then i'm going to give it the jetty dot base argument and that is going to be equal to the path to my jetty base directory so i'm going to go open up my jetty base directory and i'm going to copy this whole thing [Music] and then i need one more set of arguments and that is i need to add a few things to my jetty base directory and i'm just going to copy paste this i'm getting this from the tutorial itself because i never remember but it's it's here it's this ad module blah blah blah stuff and so i'm going to paste that in as well so i am running the start.jar file and i'm setting jetty.base equal to my jetty base directory and then i'm telling it to add modules to that jetty based directory and i'm going to run that and there you go base directory was modified so now i can go back to jetty base and now i can see that there are these new directories in here and you can you can look through these if you want but you generally won't have to touch them um okay so just for like the other just to demonstrate the other way so right now what i did is i started from jetty home and i ran start.jar pointing it to jettybase you can do it the other way around so let me demonstrate that so first i'm going to kind of delete these and it's as if they were never there jetty base is no longer initialized so now what i'm going to do is open up a command line to this directory to my jetty base directory and there's nothing in there right now and i need to run the start.jar file from here so i need to do java dash jar and i can't just do start.jar here because that file is not in this directory i need to give it the full path to to start.draw over here and there we go that's really annoying um let me do it let me just reopen it there we go and so uh the the full path of the jar which is going to be that whole thing desktop jetty home blah blah jar sorry start touch r and then i so i no longer need to give it the jetty bass argument because i'm already in jettybase and so the only thing i need to do is give it that add module argument so i'm running the jar i'm already in jetty base i'm running the jar in jetty home and i'm adding some modules so i'm going to hit enter here and the base directory was modified again and now you can see that those those directories are back and so you know you can do it either way it doesn't really matter they they have the same end result um so it's kind of you know it's kind of up to you um all right cool so i've initialized jetty bass and you can you can look through these if you want i think web apps are going to be empty um you can look through these i actually don't even really know what these are because i never have to look at them so this is you know some properties that you can probably change if you want to uh we won't need to today start.d probably contains some other startup things um yeah you know nothing too exciting um but you can look through them if you're curious so now i've got my jetty bass and what do i want to do now so the next thing i want to do is run jetty so what we've done so far is just kind of initialize jetty and the next thing i need to do is run start.jar again with kind of a similar idea where i need to either run it from you know from jetty home giving it the jetty based directory or i need to run it from jetty base giving it the full path for start.jar so let me just see what command line i already have open um so i've already done it this way so i'm just going to do it this way so basically what you need to do is run the exact same command only get rid of the add module stuff add module tells the start.jar file to initialize jetty if you don't have that then it's telling it to run jetty so i'm in jetty base and i'm giving it the full path to the jar and that's it that's all that's all i'm doing i'm just running the jar okay and it's pretty fast and once you see like started server at blah blah blah blah that means that your server is running and so what i can do now is go to localhost colon8080 [Music] and we see this error message and believe it or not this is actually a good thing this is not me messing up like i do in every single video this is actually what we expected to see and the important part here is that like you see this kind of error page you see powered by jetty down here which means that this is actually hitting our jetty server we just don't have any files yet and to sort of prove that that's true what i can do is kill my server by hitting control c in the command line and then i'm going to go to localhost 8080 again and we'll see kind of a a different error message which we'll say like this this whole server this this server does not exist there's no connection here uh so when i run jetty and then i go back here then you see you know you see this error message we're saying yeah i connected to your jetty server but there's no files in your jetty server so i don't know what you want me to do all right so the next thing that i want to do is you know add some files here and the way you can do that is exploring your jetty base directory let me close out some of these windows are getting annoying you see this web apps directory and this is where you put your files so what i'm going to do is create a new directory and i'm going to say i don't know hello and i'm going to click into that and then i'm going to create a new html file new text document sure there's a bunch of ways to do this this is how i always do it you could you know open up your favorite text editor and create it from there as well whatever yeah yeah yeah so now i have this empty index.html file and i i never i never write html by hand i i always copy paste it so i'm going to steal it from myself you can steal it from me too it's what it's here for so i want to steal some html content and [Music] i'm going to paste that into my text editor here so i've got index.html which contains this this html content and you know if you're not super familiar with html totally cool you can check out happycoding.io and check out our check out our html tutorials and whatnot but for now i'm just going to kind of stick with this kind of little file and you can probably guess it a lot of the tags in there anyway so i've got my web app hello and i've got index.html so that means that i can go to slash hello slash index.html and i should i do i see the html content that's in the file so what we can do is you know maybe edit this html a little bit i am a jetty server and i saved that and it's complaining for some reason and i think i can probably guess that why but we're going to just try it again um right so if this happens it's probably because your server's still running so you can sometimes just kill your server then save it and then re-run your server it kind of depends on your um your operating system and your your text editor settings and a bunch of things but if it happens don't panic uh kill your server save your file and then and then you can refresh and now we see our uh message that we added to our html and so that workflow is going to be pretty common where you edit your content over here and then you run your server again and then you click refresh and you see your changes um other than that let's see so in this web apps directory you can also put other types of files so you can put image files you can put css files javascript files all that stuff that um if you've done sort of client-side web development that you that you've already used and if you haven't used it yet then yeah like i said go check it out uh but you can put any file in here and it'll sort of behave exactly the same where it'll be served at this sort of uh this this url which is based on the name of the directory so this is the name of your web app in our case we chose hello and you might not like that you might not want this hello you can have multiple web apps running on your computer and that can be handy if you if you're doing something that involves like multiple things running at once but a lot of people all they want is a single web page or a single web app and they don't really want this like sub path part in their url and if that's you then what you can do is this is probably going to yell at me so i'm going to kill my server first uh what you can do is basically rename your web app directory and name it to something uh special it's root i don't think the capitalization matters but most tutorials you see you'll use all caps and now i'm going to run my server again and what i should be able to do is get rid of this hello and yeah cool so now you see that because i use this kind of magic name anything that's in root will be served from the top of the url so after the 8080 part without any sub path information in it and i'm actually curious about something that i have never actually tried before yeah yeah yeah um and that is what happens if i try something like this i honestly don't know what's going to happen so i'm going to go back here and i'm going to rename actually i'm going to close out yeah i already did i'm going to rename this to hello again so i've lost my sort of root web app and what i'm going to try to do is create a create another file here i'm just curious i just want to see so what happens if i do let's call it something like test and now i'm going to run my server again okay and i want to try i just want to see i just want to see what happens test.html does this work no okay so you need your files to be inside of a web app directory you can't just put them at this top level um so you know keep that in mind uh so if you if you don't want the path then use then use root and that's that's totally fine all right let me make sure that i didn't break anything i'm going to run my sir actually it's already running cool and let me go back to index.html and there we go okay so i've got my web apps directory and i've got my root web app directory and then i have index in there let me just double check see if there's anything else that i missed that i wanted to talk about no that's about it so there are a bunch of things you can do from here this is scratching the surface of getting jetty downloaded and installed and running the first web app but from here you can start to get into server-side coding and let me go to happy coding and if that's if that's what you're looking for then you know there's a bunch of drawers here check that out or i'll put out another video pretty soon and other than that you can also play around with like client-side web development just by putting in more files in here so images js css that kind of thing but for now i think that's where i'm going to call the video so if you were looking to download jetty and get your first web app running and kind of get through this confusing jetty home jetty base thing hopefully this video helped and i'll see in the next one so thanks for watching have a great day and as always happy coding
Info
Channel: Kevin Workman
Views: 843
Rating: undefined out of 5
Keywords:
Id: AHg16NjiSwI
Channel Id: undefined
Length: 17min 55sec (1075 seconds)
Published: Wed Jul 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.