Saturday, November 28, 2009

Customizing an Eclipse distribution

When I do Java development I usually use Eclipse. When you’re working with a team, I’ve found it’s really helpful to make sure everyone is using the same version of Eclipse with the same plug-ins and settings. In order to do this you can just package up a few more things with the Eclipse distribution. Since I’ve done it several times now I thought I would document what you have to do. I thought others might find this useful, also.

Setting up the workspace

The first thing I like to do is to build a workspace that goes with Eclipse so I can setup all the settings in the workspace. Doing this for things like code formatting and templates ensures everyone’s code will look as similar as possible. There’s also a lot of other settings you may want to setup so no one else on your team will have to.
To do this just download the distribution of Eclipse you want to start with and unzip it (for this example I’m using Eclipse IDE for Java EE Developers version 3.5.1). Then start Eclipse. Since this is the first time you will be opening Eclipse it will prompt you for where you want your workspace to be. Just clear out want it in the box by default and type ‘workspace’ and check the box at the bottom that says ‘Use this as the default and do not ask again’. It should look like this:
create-workspace
Click OK. Eclipse will then create a folder called ‘workspace’ under your Eclipse folder. From now on when you open this Eclipse it will automatically use this folder as the workspace. Now you can install all the plug-ins you want and setup all the settings you want and they will be carried with this distribution.

Packaging the JDK

Another thing you may want to do is package a JDK up with the distribution so you know for sure that everyone is using the same one. Also, this means that Eclipse will run even if the person does not have any version of Java installed on their machine (this does introduce a platform dependency, though).
The easiest way to do this is to find a JRE you have already installed on your machine and just copy it into a folder called ‘jre’ under the Eclipse folder. When you run the eclipse.exe file it looks for a ‘jre’ folder in the Eclipse folder, if one is found, then it will launch using that JRE. However, this is often not preferable because some Eclipse plug-ins (like the Maven 2 plug-in) require you to be running Eclipse on a JDK not just a JRE. So it’s best to use a full JDK. You could just take a JDK and copy it into a folder named ‘jre’ under the Eclipse folder, but that could be misleading, and there’s another way.
Take a JDK you have on your machine and copy it to a folder called ‘jdk’ under your Eclipse folder. Also in that folder there is an eclipse.ini file that is used for setting certain parameters to the exe and the Java VM. Open that file and put these two lines at the top:
-vm
jdk/bin
This will tell Eclipse to use the VM you put in the ‘jdk’ folder.
Now you can just zip up the Eclipse folder and give it to your team.

Bonus: Bundling Gradle with the distribution

For my current project we are planning to use Gradle for our builds. I wanted to be able to bundle it with the Eclipse distribution and setup an external tool configuration so it would be easy to use for anyone else.
To do this I downloaded the latest version of Gradle and put it in a folder called ‘gradle’ under the Eclipse folder. Then, in Eclipse, I created an external tool configuration like this:
external-tool
This will work fine as long as the person that uses it has their JAVA_HOME set to a valid JRE. But we’d rather have this work without that variable set. The gradle.bat file specifically looks for the JAVA_HOME variable to be set and will error out if it’s not. You can set this value to something using the Environment tab in Eclipse, but I couldn’t find any way to get this to work in a way that would function properly on everyone’s machine. So I ended up just modifying the gradle.bat file and adding a line that sets the JAVA_HOME variable to the ‘jdk’ folder under the Eclipse folder. The modified file looks like this (the added line is in bold):
...
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.\
set JAVA_HOME=%DIRNAME:~0,-12%\jdk
...
It’s a bit of a hack, but it works. If anyone has any better ideas, I’m surely open to it.

Thursday, November 19, 2009

Passion for your craft

I've been thinking about starting a blog about technology and business for while, but never actually took the time. I decided now was a good time to do it. However, for my first post, I'm really just going to direct you over to the Software by Rob blog. If you don't read it already, you should consider it. He had an excellent post today about Passion as a Competitive Advantage. I thought it was great and truly believe in the importance of being passionate about what you do.

In the article Rob says:
Passion translates into being insulted when people don’t care about things as much as you do and are willing to hack a crappy solution together. It’s an insult to you, your product and your craft.
One thing that passionate people love is other passionate people. When you really care about what you do, you want to work with people who also care about what they do. The last thing you want is to have to work with someone who is just trying to put in their forty hours a week. And, as Rob puts it:
If you don’t have passion for your code/product/startup everyone will know. It’s obvious you aren’t that into it, and people will not take you seriously. Without passion it’s impossible to convince people to believe in your vision.
I started out in college in Chemical Engineering. I made it through my third year and was only 30 hours away from graduating. Toward the end of my third year I was sitting in a principles of chemical engineering class, and the professor was chewing us out for not putting much effort into our latests assignment. We were doing a design and analysis of a distillation column, and a lot of us (myself included) didn't do a thorough job and just turned in a half baked solution. Not surprisingly the professor, who was passionate about his field, was practically insulted by our lack of effort.

Then the professor said something that changed my path in school. Actually, he asked a question. He asked, "Why would you turn in something poorly done, if you care about what you're working on? And if you don't care, why are you getting this degree?" I sat there and thought, "That's a good question! Why am I getting this degree?" The was effectively the end of my career as a Chemical Engineer.

The summer before that I had taken a C++ class that was required to complete my ChemE degree. I really loved it. I did more than the class required, and would often just program things for fun. In one of my ChemE classes we had to write a program to solve a problem. The professor actually supplied a mostly complete program in some strange math environment and said we just had to complete it, if we wanted to do it that way. Everyone else did that, but I wrote my own from scratch in C++. I thought it would be more fun that way. Incidentally, mine was the only one that worked correctly.

So, when that professor asked us why we were getting a degree in ChemE if we didn't care about it, I decided that Computer Science made more sense. This was something I did really care about, and something I loved doing. And the rest, as they say, is history.

I graduated in 2001 with my CompSci degree and still love programming. It's been great getting paid to do something I love to do. And I've enjoyed all the time I've spent reading, practicing, and learning more about software development. 

After eight years I believe even more in the importance of passion for what you do. I love working with passionate people, and I'm always baffled by people who don't seem to care. They should have had a professor like I did and had to face the question, "if you don't care, why are you getting this degree?" If you aren't doing something you are passionate about, then do yourself and everyone else a favor and go find something you are passionate about. You'll be glad you did.