{"id":883,"date":"2015-01-29T02:37:39","date_gmt":"2015-01-29T02:37:39","guid":{"rendered":"http:\/\/mooredynasty.net\/?p=883"},"modified":"2015-01-29T02:52:42","modified_gmt":"2015-01-29T02:52:42","slug":"java-101-14-years-later","status":"publish","type":"post","link":"https:\/\/mooredynasty.net\/index.php\/2015\/01\/java-101-14-years-later\/","title":{"rendered":"Java 101, 14 years Later"},"content":{"rendered":"<p>As most of you know I am a computer programmer by trade. OK, I manage a team now, but I can still write code. C# code, that is, with all that comes with it: Visual Studio, IIS, deployment projects, Team Foundation, etc.<\/p>\n<p>So now I\u2019m taking this class at Georgia Tech in which I have to contribute to a team project that must be done in Java. The problem isn\u2019t the language \u2013 Java is arguably the 2nd best programming language going \u2013 it\u2019s the other stuff: web servers, build tools, class libraries, etc. 14 years ago I did a WebLogic project and ported it to Tomcat and WebSphere, but I\u2019ve forgotten almost everything about that ordeal.<\/p>\n<p>Today I managed to get the obligatory \u201cHello World!\u201d app up and running. Big deal. And yet, some interesting lessons came from that.<\/p>\n<p><strong>Maven<\/strong><\/p>\n<p>First, Maven is pretty cool. My understanding is limited, but getting going is easy:<\/p>\n<ul>\n<li><a href=\"http:\/\/maven.apache.org\/download.html\">Download<\/a> <\/li>\n<li><a href=\"http:\/\/maven.apache.org\/download.html#Installation\">Install<\/a> <\/li>\n<li><a href=\"http:\/\/maven.apache.org\/guides\/getting-started\/maven-in-five-minutes.html\">Quick tutorial<\/a> <\/li>\n<\/ul>\n<p>After perusing these docs I was able to create a project in Maven structure:<\/p>\n<blockquote>\n<p>mvn archetype:generate -DgroupId=edu.gatech.ateam.helloworld -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false<\/p>\n<\/blockquote>\n<p><strong>Lesson Learned<\/strong>: Don\u2019t use dashes in your <em>groupId<\/em>.&#160; That might be OK if you specify a dash-less <em>package<\/em> parameter, but definitely not OK per the above.<\/p>\n<p><strong>JAR File Compilation<\/strong><\/p>\n<p>The Maven project generator creates the Hello World app, which then needs to be compiled. This is easily enough done:<\/p>\n<blockquote>\n<p>mvn package<\/p>\n<\/blockquote>\n<p>(Note that this is the point at which the dashed \u201chello-world\u201d <em>groupId<\/em> caused a problem.)<\/p>\n<p>When successful, Maven creates a JAR file in the project\u2019s <em>.\/target<\/em> folder.&#160; <\/p>\n<p>What\u2019s it called?&#160; helloworld.jar?&#160; No, try helloworld-1.0-SNAPSHOT.jar on for size.<\/p>\n<p><strong>Execution<\/strong><\/p>\n<p>Given a nicely compiled project, all we\u2019re left with is the simple task of running it.&#160; What could be easier? Alas, in Java it\u2019s not a simple double-click.<\/p>\n<p>Given that the JAR name and <em>groupId <\/em>are as given above, change to the project directory and execute:<\/p>\n<blockquote>\n<p>C:\\Deve\\CS6440\\helloworld&gt;java -cp target\/helloworld-1.0-SNAPSHOT.jar edu.gatech      <br \/>.ateam.helloworld.App<\/p>\n<\/blockquote>\n<p><strong>Lesson Learned<\/strong>:&#160; I had a Java.exe and Javaw.exe in my C:\\Windows\\System32 folder, which were causing a <a href=\"http:\/\/stackoverflow.com\/questions\/15277496\/registry-key-has-value-1-7-but-1-6-is-required-java-1-7-is-installed\">what is evidently a common Java version error<\/a> when running the app. <\/p>\n<blockquote>\n<p>error: registry key &#8216;software\\javasoft\\java runtime environment&#8217;\\currentversion&#8217; has value &#8216;1.8&#8217;, but &#8216;1.7&#8217; is required. <\/p>\n<\/blockquote>\n<p>At first, deleting the rogue Java executables made things worse because no Java was found at all.&#160; Adding the <em>C:\\Program Files\\Java\\jdk1.8.0_31\\bin<\/em> folder to Windows\u2019 PATH solved the problem.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>\u201cHello World!\u201d indeed.<\/p>\n<p>Next steps are to port Hello World to the web, create a WAR file using Maven, register the app as a Tomcat application, deploy it, and watch the sparks fly!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As most of you know I am a computer programmer by trade. OK, I manage a team now, but I can still write code. C# code, that is, with all that comes with it: Visual Studio, IIS, deployment projects, Team Foundation, etc. So now I\u2019m taking this class at Georgia &hellip; <\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-883","post","type-post","status-publish","format-standard","hentry","category-development"],"_links":{"self":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/comments?post=883"}],"version-history":[{"count":10,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/883\/revisions"}],"predecessor-version":[{"id":893,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/883\/revisions\/893"}],"wp:attachment":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/media?parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/categories?post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/tags?post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}