On to Spring

On to Spring

My attempt to throw myself headfirst into contributing to an open-source project didn’t go quite as well as I hoped.  I think I just need some more practice using other open source software in my projects.  With that in mind, I’m turning towards the Spring framework for Java to help me out with some of these things.

Surprisingly, the Spring site is incredibly robust with tutorials about how to deploy stub Java classes with embedded Apache Tomcat or Jetty servers.  I was futzing last night with simple hello world and other simple projects, just getting it up and running and familiar.  Along the way, I’ve picked up a host of other open source tools as I dance around with deployment via Heroku.  Let me tell you– Heroku is fabulous stuff to me right now.  It makes deploying a quick containerized Java web app easy right up on AWS with a great hobbyist tier so I’m not incurring anything.

I’m becoming more proficient at using Brew to find other packages that I may not have– I’ve been working with PostgreSQL, the Heroku toolbelt and the Springboot components all from within the CLI.

I think I have an incoming project where Spring will probably be the easiest and most useful framework to solve the problem.  I’m actually coming to enjoy doing some of my webwork in Java now that I’m not trying to screw with the stock JDK libraries for things. Its nice not to be treated like a second-class citizen for wanting to work in a language that I already know so well.

Apache Maven & Homebrew

The OK-HTTP project lists that I can compile this project using Maven.  The Maven project is a build tool for (primarily) Java projects.  It provides a dependency list of other bits of compiled code and pointers to how to fetch them for a compile.  There is an alternative tool called gradle, but I’m not going to delve into that that.  I’d love to learn it at some point but I’ll stick with Maven.

Let’s check and see if I’m running Maven already: 

mv --version

.  I get an error back that signifies that I’m not running it on my local machine.  Ok, very well let’s go grab it. This seems like a good time to mention Homebrew, an package manager for OSX.  The description of Homebrew on the official site is that it gives you all the programs and tools that Apple took out of of OSX.  It is command line based, and it’s a quick scripting engine to find common projects and libraries and compile them and any dependencies they may have.  Its very straightforward to install, and you can query it for formula (read: software packages) that they have by running:

brew search maven
brew install maven

 At the end you’ll have a version of Maven installed in your “cellar” under “/usr/local/Cellar/…”  The idea is that programs compiled or installed by Homebrew shouldn’t interfere with a possible prior installed version in the normal “/usr/local/…” directory.  In this way there’s no real conflict if some other app also happens to install maven in the default directory.

Alright, so first up I’ll rerun the “mvn –version” command.  This tells me that unfortunately the version of Java it found on my $PATH is the default Apple provided version, JDK 1.6.**.  That’s definitely not very useful because the OK-HTTP project requires compiling against Java 7, and even I’m running the latest sub-version of Java 8.  Apparently this is common enough that someone has written a shell script to solve this here.  It looks legit, and I’ll tweak it to look for Java 1.8.  Success!  Here is the result of Maven now reporting the correct version:Switch JDK Version

Alright, clone the project and let’s see what we’ve got here.  I’ve followed the “Get up and running with Maven in 5 minutes” tutorial here, which gave me everything I needed (I think).  I created a Maven “goal” to create a stubby simple HelloWorld app.  This gives you a nice organizational tree and a basic JUnit test for that same basic Java class.  It also creates a pom.xml file which is how Maven configures your project.  It’s actually relatively simple– there is a key called “dependencies” and that’s where you can specify that during a build/compile phase of your project, that it reach out and grab a specific version (or the newest) of a JAR to compile your code with.  This makes it really easy for us to add the Ok-HTTP code as a dependency to the project with just a few lines.

Here’s the code I added to my pom.xml file: 


Once there, I asked Maven to go compile my project once again using “mvn compile”, which gave me a successful compilation and the following result:OK-HTTP Maven

I’m now feeling pretty good with the basics of Maven.  If I was to use this in a Java project I could start a project in Maven, do my normal source code, and compile and build against these references to someone else’s code.  I’m ok with that, but honestly (and don’t shoot me), I do most of my Java code in the Eclipse IDE.  Considering this whole project structure that Maven implemented is still different than the Eclipse project structure, (which is in itself different than the Git blob structure) I’ve got some more work ahead of me.

Contributing to Open Source

Contributing to Open Source

Well, another quarter is behind me.  I have like 2 weeks to try and decompress and get ready for the new quarter. I’m not sure if anyone truly decompresses from this stuff though– I think part of me is afraid to let it all go because its definitely the meaty stuff that shows up in a technical interview.  As a way of “relieving the pressure” so to speak, I’m going to try and improve my standing on GitHub today.  As CS undergrads we constantly hear that we should be contributing to open source projects, and to show off your GitHub profile when talking with prospective employers.  So today I’m going to try just that.

The irony is that there are a ton of articles online about “How to get started with open source” and they mostly involve working with a project you’re already using or are interested in.  Unfortunately for better or worse, most of my college career hasn’t been spent using third party libraries or consuming other people’s code, at least not on the surface. I am well aware that right underneath the surface of my OS there is a world of open source libraries and functionality.  My intent is to write about what I come across as I attempt to do something simple like “contribute to open source”.

The basics: Here is my GitHub profile page:

Those squares should be green....

Those squares should be green….

It’s beautiful isn’t it? I’ve got a streak of pushing code to a repo of 1 single day. Ha!  Let’s change that.  GitHub suggests you search or explore the site by specifying a language.  I’ve spent the last 2 years in Java and I’d rather not be thrown a curve-ball today.  Looks like Square has a project called Ok-HTTP which handles HTTP requests via SPDY.  SPDY‘s goal is apparently to reduce web page load time and optimization over the HTTP interface.  Ok, sounds simple enough.  Who doesn’t want to make web connections faster?

I think my peers would say my “git-fu”, i.e. the amount of skill I have using Git is probably fairly high.  I can definitely grok the command line stuff, but I prefer to use the implementations within Eclipse or even Atlassian’s excellent SourceTree application.  I can either grab this thing as a pre-packaged Java JAR (compiled obviously) or I can grab the source through something called Maven.  Hmm…Looks like thats the first place I need to go.

Effective Java (2nd Ed.)

Effective Java (2nd Ed.)

As a Computer Science student, I think we’re expected to hold a very large library of books.  Some are required textbooks for classes, and others are indispensable bundles of text that we just happen or or passed through the grapevine.  For me, this book is the former.  Effective Java by Joshua Bloch is one of the most indispensable textbooks I’ve ever read on the Java language. (more…)