RESTful With Spring

I’ve been exploring RESTful with Java using a local Apache server. My first attempt using this guide failed. I was able to install and run an Apache server using Eclipse, but couldn’t get the annotations on the app right, and the server couldn’t find my class.

My second attempt was much better, partly due to Spring’s simplicity. I followed their RESTful tutorial and had a server up and was running a local web page in about an hour.



I ran into a few bumps related to Maven version and path. First I installed Maven 2, which turned out to be a bad move; I didn’t realize Spring was configured for Maven 3. When I tried to build with Maven 2, I got the following error:

Once I realized the problem was Maven 2, I installed Maven 3, which apparently is the package maven, and not maven2. Apparently maven is the most recent version, while maven2 must be a branch for support of legacy software. Anyway, just installing maven wasn’t enough, as the error persisted. Spring was still accessing Maven 2 through the path, so I tried purging maven2, and the package command worked! Check out

I took a break at this point. The next day, I made a few changes to get more familiar with the classes and controllers, then tried to $ maven package, and got the infamous class not found error: Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher.
It turns out the path was incorrect, most likely from my initial botched Maven install. I’m not sure why it had worked the day prior. It’s possible that the Maven path update from the Maven 3 install only persisted through that bash session, and was lost when I restarted. The path had an extra directory in the Maven 2 variable, so I simply created that directory and moved the binary files to it and it compiled! I’ll do a little research to see if I can reproduce the steps that caused the ‘class not found’ error.

These stumbling blocks with Maven bothered me. Clearly I needed more information on using Maven, so I did a quick search of the Spring guides and Lo! How to Maven! The guide walked me through a very basic Maven app build. Meanwhile, I’d been listening to some more of the How to Program with Java podcast, and Trevor had a couple helpful episodes about Spring specifically, and even covered down on Maven at the end of the second episode. I always find when learning something new that everything clicks faster if I can see the information presented from multiple sources, then try and fail at it a few times.



Next I tackled the Consuming a RESTful Web Service Spring guide. This time, instead of cloning the repo I built the project from scratch through the terminal. The build was a breeze since I’d already worked out the Maven kinks. I even manipulated the JSON output of the previous project to match the expected consumption format, ran the server, then consumed the service from a separate terminal window! Awesome! Of course the value was null because I didn’t get the nested JSON right, but it still read the page from my service!

Github here.


Setting up an MVC

Of course, the goal is to figure out how to build a web page similar to what I’ve done with my Django projects. I’m getting a little closer after following the Serving Web Content With Spring MVC guide.

MVC: Model View Controller design pattern.

I completed this project entirely through the terminal, and since it was similar to the previous RESTful projects, didn’t really run into any issues of note.

Github here.


Matthew Odle

Indie dev, autodidactic polyglot, lover of programming, dad, musician, writer, mentor

Join the Discussion