Last time I wrote about Creating a Build.vNext agent on Linux. I ended that post with the idea to build a Java application on Linux. The first thing that we’ll need is some Java code in VSO to build. Being a Java newbie, it took me quite a bit of figuring out on how to do that. I thought I’d share my experiences here, for you to enjoy.
Install Eclipse and Team Explorer Everywhere
The first thing you’ll need to do when working with Java is installing a Java IDE. You can download it from here. I chose to download the “Eclipse IDE for Java EE Developers”, since that already includes some things that are usefull later (like Maven integration). Installation is as simple as unzipping the files to a folder of your choice. However, I did have a strange issue when using the default Windows unzipper, resulting in Eclipse not starting up. When using 7-Zip, all is fine. Once you get Eclipse running, you’ll see a nice empty interface.
Next we’ll install Team Explorer Everywhere. Go to “Help”, “Install New Software…”
Then click the “Add” button to add a repository.
Enter the details for the Microsoft Eclipse repository and click OK.
Next, make sure the Microsoft repository is selected, check the TFS plug-in and click Next.
After finishing the wizard the TFS plug-in will be installed and you’ll need to restart Eclipse. You can open the plug-in by clicking “Window”, “Show View”, “Team Explorer”.
Finally, click “Connect to Team Foundation Server” and select your VSO account and project.
Voilà, you are connected to VSO from Eclipse!
Upload code into repository
Before we can build something, we’ll need something to build, obviously. I’ve put a demo application on my GitHub, which you can download here. Unzip the file and put the “Demo/hellomaven” folder somewhere on your hard drive. In my case, I used “D:Demo”.
In my VSO project, I have created an empty Git repository to hold the code. We can use Eclipse to push the code there. First, we’ll need to clone the repository. In Eclipse, go to Team Explorer and click “Git Repositories”. Then right-click your repository and click “Import repository”.
In the wizard, select your repository and click “Next”.
On the next page, select a local folder where you want to clone the repository. A subfolder with the name of your repository will automatically be created. Don’t forget to provide your credentials. If the account you used to log-in to Windows is something different than what you’re using for VSO, you’ll need to provide your alternate credentials here.
Since there is nothing in the repository yet, we can’t select an initial branch…
Next, the wizard will ask if you want to import or create Eclipse projects from this repository. Since I’ll import my demo project into this repository later, I’ll select “Import detected Eclipse projects”.
Since the Git repository is empty, there will be no projects to import. That’s OK, we’ll add a project later. Click “Finish” to start cloning the repository. It’ll appear as if nothing happens, but you will get a (empty) copy of the repository on your local disk.
Now we can import our code! First, we’ll open the project in Eclipse. To do that, right-click in the Package Explorer (“Window”, “Show View”, “Package Explorer” if it’s not visible) and select “Import…”.
Select “Existing Projects into Workspace” and click “Next”.
Browse to the directory where you unzipped the demo project (or your own code of course), make sure your project is checked and click “Finish”.
This will import your project into your workspace and make it visible in the “Package Explorer” window. From there, we can move it into our Git repository. Right-click the project and select “Team”, “Share project”.
Select “Git” as the repository type and click “Next”.
Select your repository in the dropdown list, make sure your project is checked and click “Finish” to move the project into the Git repository.
Now all we need to do is commit and push our code to VSO. To do that, right click your project and choose “Team”, “Commit”.
Type a meaningful commit message (you always do this, right?), select all files and click “Commit and Push” to start pushing everything to VSO.
Since this is the first time we’re pushing, we’ll need to select a remote branch to push to. In this case, I’ll go with the default “master”.
Finally, click “Finish” to start the magic…
If everything went smoothly, you’ll get a result window without any errors.
You should also see your code in the “Code” tab of the VSO web interface.
So that’s it! You now have your Java code in a Git repository, hosted on Visual Studio Online! You can now start using Git from Eclipse, where all the usual Git stuff (commit, branch, merge, history, rebase, etc) is available under the “Team” submenu in the “Package Explorer”.
You can also use the “Git Staging” view, which will give you a nice and easy way to select the files that you want to commit. Just drag files from “Unstaged Changes” to “Staged Changes” to include them in your commit.
Hopefull this will get you up and running with Eclipse, Git and VSO quickly! My next post will be about using VSO Build.vNext to actually build the code.