{"id":472,"date":"2017-06-05T19:23:41","date_gmt":"2017-06-05T23:23:41","guid":{"rendered":"http:\/\/www.tayloraliss.com\/blog\/?p=472"},"modified":"2017-06-06T23:31:19","modified_gmt":"2017-06-07T03:31:19","slug":"phase-1-complete","status":"publish","type":"post","link":"https:\/\/www.tayloraliss.com\/blog\/?p=472","title":{"rendered":"Phase 1 Complete!"},"content":{"rendered":"<p><a href=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2017\/06\/18927079_10101251932634176_1259942473_o.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-473 size-large\" src=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2017\/06\/18927079_10101251932634176_1259942473_o-e1496702419715-1024x376.jpg\" alt=\"\" width=\"802\" height=\"294\" srcset=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2017\/06\/18927079_10101251932634176_1259942473_o-e1496702419715-1024x376.jpg 1024w, https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2017\/06\/18927079_10101251932634176_1259942473_o-e1496702419715-300x110.jpg 300w, https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2017\/06\/18927079_10101251932634176_1259942473_o-e1496702419715-768x282.jpg 768w, https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2017\/06\/18927079_10101251932634176_1259942473_o-e1496702419715.jpg 1681w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<p>I have been making some serious progress towards development of my app. Last night I was lying in bed configuring my Linux server on my phone with <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.sonelli.juicessh&amp;hl=en\">JuiceSSH<\/a>\u00a0and managed to get Tomcat set with Spring Boot. I was able to display a simple &#8220;Hello World&#8221; message when I visited\u00a0<a href=\"http:\/\/104.131.74.25:8080\/\">104.131.74.25:8080<\/a>\u00a0which is a huge step forward. Doing so took a good amount of configuring however. Here are some of the challenges I faced just to get this far:<\/p>\n<ul>\n<li>I was dead-set on using IntelliJ IDEA to setup Spring as I prefer it to Eclipse. However, in order to have\u00a0Spring baked into IntelliJ by default, you need to have the IntelliJ Ultimate which is $12\/month or $50\/year. Luckily, because I am still a student at Oregon State University, I\u00a0am <a href=\"https:\/\/www.jetbrains.com\/student\/\">able to use IntelliJ for free<\/a>! Score!<\/li>\n<li>I followed\u00a0<a href=\"https:\/\/www.youtube.com\/watch?v=Ye3dfrrEPCg\">this video<\/a> for instructions\u00a0on how to set up a simple &#8220;Hello World&#8221; using Gradle and IntelliJ. It worked on localhost and I attempted to port it over to my server by just copying the whole directory over. I would later learn that this is\u00a0not the proper way to do things.<\/li>\n<li>Once I had ported over my project, I installed Tomcat, Gradle and Spring. However, I had issues with Gradle and Spring because their versions were too old to be compatible with my Tomcat installation, so I had to manually download the latest versions from the companies&#8217; websites. I learned a valuable lesson in this &#8211; you can&#8217;t always trust the package manager for the latest version of software.<\/li>\n<li>I was finally able to get the server up and running by typing <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">gradle bootRun<\/code> in the project directory! Victory&#8230; or so I thought!<\/li>\n<li>A very helpful redditer <a href=\"https:\/\/www.reddit.com\/r\/springsource\/comments\/6fb0bv\/how_do_i_get_spring_to_run_on_linux\/dihj1mg\/\">informed me<\/a> that my setup was erroneous.\u00a0Here&#8217;s the advice he gave me:<\/li>\n<\/ul>\n<blockquote><p>You should be building a .jar (locally or somewhere else) and then uploading that jar to your server. You really shouldn&#8217;t be using gradle to run your application on the server. <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">gradle bootRun<\/code> is just an easy way to get your app running locally for development purposes.<\/p>\n<p>You can build a .jar locally using\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">.\/gradlew build\u00a0<\/code><\/p>\n<p>Then you will find a .jar file in <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">build\/libs\/<\/code> that you can upload to the server.<\/p>\n<p>You also need to run your app as a service. Simply executing the app on the command line like you are doing is great for local devlopment, of course, but it won&#8217;t work on a server. In fact, as soon as you <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cntrl+c<\/code> or disconnect from the server, your app will shut down. This is why you need to run it as a service.<\/p>\n<p>Thankfully, doing this with spring boot is actually pretty easy even if you aren&#8217;t very familiar with linux:\u00a0<a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/deployment-install.html\" rel=\"nofollow\">https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/deployment-install.html<\/a><\/p>\n<p>That documentation gives you two methods, <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">init.d<\/code> and <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">systemd<\/code> (don&#8217;t worry too much if you don&#8217;t know what those mean right now). You probably want <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">systemd<\/code> unless your Debian is an older version that doesn&#8217;t support it (in which case use <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">init.d<\/code>).<\/p>\n<p>Essentially what spring boot does it allow you to build a fat jar that is also an executable that can be run as a Linux service. You then create a configuration file (<code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/etc\/systemd\/system\/yourApp.service<\/code>) where you point to that fat jar, and in that file you can also control stuff like where your output will go.<\/p>\n<p>Once you do that, you can start your app like:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">systemctl start yourApp.service<\/code><\/p>\n<p>You&#8217;ll notice it will give you back the console and run the app in the background. You can see your output in various ways (look at the documentation, usually a file somewhere in in <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/var\/log<\/code>).<\/p>\n<p>You can also &#8220;enable&#8221; the service<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">systemctl enable yourApp.service<\/code><\/p>\n<p>This will make it start up automatically whenever the server starts up or restarts.<\/p><\/blockquote>\n<p>I followed his advice and the documentation he linked me and managed to get things working. This required me to\u00a0add code to my build.gradle file and to run <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">gradlew build<\/code> to get a .jar file. I copied the .jar file over, created a .service file and started the service with <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo systemctl start myapp.service<\/code>. I had to fix some errors with the service as it wouldn&#8217;t start right away which included making the .jar executable by typing\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod +x \/var\/myapp\/myapp.jar<\/code><em>\u00a0.<\/em>\u00a0I also learned:<\/p>\n<ul>\n<li>To see what services are running with the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">systemctl list-units<\/code>\u00a0command<\/li>\n<li>To see details about a service using <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">systemctl status -l myapp.service<\/code>.<\/li>\n<li>To see what ports are being listened on so I can make sure Tomcat is running using <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo lsof -i -P -n | grep LISTEN<\/code>.<\/li>\n<li>To restart a service, use <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo service myapp restart<\/code><\/li>\n<\/ul>\n<p>I learned a lot setting this up, but now I get to move on to the fun part of linking the app to the back-end.\u00a0I am looking forward to it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been making some serious progress towards development of my app. Last night I was lying in bed configuring my Linux server on my phone with JuiceSSH\u00a0and managed to get Tomcat set with Spring Boot. I was able to display a simple &#8220;Hello World&#8221; message when I visited\u00a0104.131.74.25:8080\u00a0which is a huge step forward. Doing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-472","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=472"}],"version-history":[{"count":10,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions"}],"predecessor-version":[{"id":483,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions\/483"}],"wp:attachment":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}