This post is the result of trying to figure out how to setup a repository clone of one of my projects on my windows machine. I work on my Mac most of the time, but at times it’s more convenient to work on my Win machine (usually when I have to debug IE issues, and need to try js fixes to see what impact they make)
So, lets start by setting up our tools and IDE on Windows. We obviously need Java, Eclipse, and Maven, and actually that’s it. In Eclipse, install m2e and EGit plugins. Make sure you follow all the installation instructions for Maven with all the variables in the right place.
Now we need to setup SSH. This needs to happen in two places, in Eclipse settings and in Cloudbees settings. Here are the steps:
- In Eclipse, go to preferences->General->Network Connections->SSH2, select key management, and generate a DSA key. Enter the pass phrase and remember it, you’ll need it in a minute. Copy the public key to the clipboard.
- Click “Save private key” and save it, go to general and add the saved private key. Apply and save.
- Go into Cloudbees settings->SSH keys, choose a name and paste the public key from the clipboard. Click “Add”.
- Go to Cloudbees->Repositories, go into your project and copy to clipboard the SSH url unique to your repository.
- Go back to Eclipse, File->import, choose Git->Projects from Git. Choose URI and paste the SSH URL you copied from your repository. Choose ssh as the protocol. The user should be git, and password empty. Port can remain empty (it will be filled with the default which is 22)
- You will now need to enter your pass phrase.
- Next next next and your project will be cloned locally.
- To help maven work you need to go into Eclipse->Preferences->Maven, and go to installation->Add and pick the Maven installation you installed locally (instead of the Embedded one).
- If you run into problems with your project when you open the IDE, see this post. If you still have problems, and you had Maven installed before, try deleting the .m2 resources directory. You might also need to go into Preferences->Maven->User settings and reindex or update settings.
- Your project should automatically compile.
Problems you may encounter:
1. M2E installation fails and maven does not seem integrated into eclipse. I couldn’t fix that and had to reinstall eclipse
2. You get complaints about javac and JRE: you’re using JRE instead of JDK, switch to JDK in eclipse->java->installed jdk’s
In the previous post of this series, I talked about the different technologies we’ll be using and the sample project which is freely available, in this post we’ll cover the basics of setting up a functional development environment, one which will allow you to develop and instantly deploy your code to production so it is available to the rest of the world.
I think that the hardest thing about starting a new service for the first time is, well, getting started. If you’re a seasoned developer, you’ve done a couple of things in your life, maybe even led some projects, you feel you can do anything. But when starting out on your own, you are faced with a challenge you haven’t faced before. In most cases, even as a fifth or sixth developer at a startup, there’s a skeleton on which you work. Somebody already setup the framework, built the necessary scripts, setup the build/deploy process, created the minimal classes. Your job is now to add the functionality, possibly adding new infrastructure that was never there, but most times there’s something to work on top of.
For a completely new service there’s nothing. You need to download the IDE, set it up, configure your application from scratch, deploy it somewhere (locally or all the way to production), and make it work.
You can check out my post on some of the tools we’ll use just to get a general idea of the different stuff you might need to install at different stages of your project. One thing to notice, all of the tools I’m going to use in this series of posts are free, open source tools, or those that are free for use by small startups which are just getting started. You might need to pay for it at some point when your project grows, but not right now.
You’ll need to do the basic stuff of getting an OS (virtual or real, preferably Unix based, I use Mac OSX, but Ubunto is a good choice for development as well), installing JAVA, a basic text editor, and some kind of image editing software (you can get adobe photoshop for a free one month trial, more than you’ll ever need for starting out). I use Chrome for all my browsing, if you’re on Windows you might still be using IE, but as it is no longer the most popular browser, I suggest switching to Chrome for the initial testing stages of your work.
So once you have all those setup, you’ll need an IDE. You can checkout my short post on choosing an IDE, I personally believe that for a startup Eclipse is more than enough. I use “Eclipse Java EE IDE for Web Developers.”, you should get some plugins installed, at least EGit (git support) and m2e (maven support).
Next step is to get source control software, I use GIT and the Basic Service project is hosted in a GIT repository on Google code, but Subversion is a decent choice as well. After that, install Maven, you’ll use it extensively. Last thing you will need to go through this tutorial is SSH, this will be used for deploying your work to production (cloudbees uses SSH for its repository communication). Note that I’m using Cloudbees as the git repository, it’s also possible to use GitHub and run from there but we won’t cover that right now.
So now you can checkout stuff, and open it in your IDE, that’s cool. You might be tempted to install an application server like Tomcat, and that’s ok, but it’s not really needed. Jetty is a very good application server which you can use directly from your IDE and it will automatically update your project as the source changes, and you can run it using project configuration only (maven FTW). We’ll get to that later, for now, let’s leave Tomcat out of the equation.
At this point, the best thing for you to do, is watch a video! Not just any video, you should watch this one. This is one of the most useful tutorials I’ve ever watched, it will take you from (almost) zero (where you are at right now or at least where I was when I started) to 100 (a fully operational, continuously deployed project) in 30 minutes (actually 26).
Come back when you’re done (meaning you followed the instructions, setup everything, built and deployed it to production, and it works for you).
So now you’re a couple of steps further than you’ve been when you started reading. You already have your work environment setup, you’re compiling and deploying an app to production, you even have it saving stuff to a production repository.
Next you’ll want to setup your local environment so you can test stuff locally. You’re almost ready, just need to install MongoDB so you can point your application to your local DB instance (it will also work against the instance on Cloudbees if you prefer, but I’d rather have my local instance which I can play with and explore). So once that’s installed, try to get it running and point your app to use the local instance. When that’s done, if you’re on a laptop like me, it means you can work from your favorite spot (on the beach?) and not require an internet connection to develop stuff.
Great, we’re ready to move on. The next post will talk about getting the Basic Service project over to your development environment, and setting it up so you play around with it and learn the technology involved, or even start developing your own online service.
I decided to clone my base project (basic service) to start a new project, so I used git to fetch it to my local drive, then tried to import to my workspace using file->import->maven->existing maven projects. Picked my new cloned project, and indeed the POM.xml file appeared, but the checkbox next to it was unclickable! Of course eclipse won’t tell you why, so after searching the web and trial and error, I finally figured it out:
If you already have a project by the name specified in the POM, you can’t create a new one with that name from the POM.xml
In order to get through this issue, you need to add a suffix in the Advanced->Name template field (just adding “clone” was enough for me) or change it in the POM.
In the coming series of posts, I will share my development experience (code included) with creating an online service from scratch. If you read through all posts, you should reach a point where you are capable of writing code and deploying it to a production like environment which is available online, using some of the latest (and greatest) open source libraries available in java. You will definitely not be at the end of the journey, but will get a pretty good head start.
I’ve created a sample project, which basically does nothing (well, almost nothing), but it does so in a (semi) secure way, using several top libraries. Basic service, is a service which lets you register, login, and… do nothing. But, it does so using:
Spring, Maven, ESAPI (+AppSensor) for input validation, JSP’s (JSTL+Tiles 2), jQuery (+UI), Mongo DB, Logback, Jackson, Mockito (+PowerMock) for unit testing, and it does it in a RESTful way, using complete Data and Presentation separation (all JSP’s get their data through REST requests, meaning you can add easily add mobile support without almost any change to the interface), and is fully internationalized (currently supports hebrew and english, meaning we have RTL languages covered). The complete source code for Basic service is available on google code, it is a fully functional (and GPL open source) example of combining all of these technologies , which means that you can concentrate on the next steps rather than spend time building the foundation from scratch. It took me about 3 months to go through all the baby steps in each of those technologies (after spending some time picking the right ones of course), I hope this series will save you at least some of that time.
Please keep in mind that I do not claim this to be a complete and bullet proof piece of software, there is still much to do in order to make it “production ready”.
One final note: the title says “a beginner’s guide”, but should be read with two different interpretations: one is (possibly) you, who is just getting started with creating an online service, and the other is me, sharing my experience with jumping into these deep water a couple of months ago. If you like what you read, you’re welcome to comment, if you see me making horrible mistakes, constructive criticism is more than welcome.
Let’s move on. The next post will cover the basics of setting up a functional development environment, one which will allow you to develop and instantly deploy your code to production so it is available to the rest of the world
This happened to me today: I added google Guava to my pom (for using their ImmutableSet collection), maven imported the jar correctly, but for some reason Eclipse refused to show it in the maven dependencies list, and the ImmutableSet import did not work (would not show me the option to add a java import statement, and adding it manually did not find the google library).
The reason for this eludes me, so can’t solve the bug, but I do know a quick work around:
- close Eclipse
- go to the project directory
- in terminal, enter:
- do NOT run mvn eclipse:eclipse as this will create an eclipse project which has a weird structure in eclipse, instead, do the following:
- re-run eclipse, go to file->import, select maven->existing maven project, choose your project directory, eclipse should recognize your pom, click finish, and voilla, your project will start working again.
This will probably work for any unclear state the project goes into in eclipse, not just import issues.