Search This Blog

HOWTO: Setting Up a New Ubuntu GNU/Linux Box for Java/CFML Development

Since I wind up doing this every six months with each new release of Ubuntu, I thought this time around I'd document how I set up an Ubuntu GNU/Linux box for Java and CFML development. This is partly so I don't scratch my head thinking "was there anything else?" next time, but mostly for people who want to dive into GNU/Linux from another platform and need a quick step-by-step guide to help them get productive quickly.

Note that if you're setting up an Ubuntu server, the server-related stuff that follows (Apache, Tomcat, and MySQL) will be pretty much the same on a server as it is on a dev machine with a couple of differences. First, you'll want to have Tomcat autostart at boot on a server (which I don't do on my dev machine). Second, and this is a matter of personal preference, I tend to put Tomcat in my home directory on my dev box, but in /opt on the server.

So open up a terminal and let's the the easy apt-get stuff out of the way first.

INSTALL APACHEsudo apt-get install apache2

INSTALL MYSQLsudo apt-get install mysql-server mysql-client

INSTALL VIM & EMACSsudo apt-get install vim emacs

You can also install Java and Tomcat via apt-get, but I prefer to download these items directly from their respective sources. We'll start with Java.

DOWNLOAD/INSTALL JAVA

Open a browser and go to http://java.sun.com (sorry Oracle, I'm not using your URL until you turn this one off!)

Mouse over "Downloads" and click on "Java for Developers"

Scroll down a bit on the next page and click on the "Download JDK" button (you'll want the full JDK, not just the JRE)

On the next page, click on the Platform button and choose either "Linux" (32-bit) or "Linux x64" (64-bit) as appropriate for your machine. Then scroll down and hit the "Continue" button.

Under "Available Files" on the next page, click on the .bin file, not the .rpm.bin file.

After the download completes (and I'm assuming you downloaded to your Downloads directory), open a terminal and do the following, hitting enter after every line (note the file name may be different based on the version you download): cd ~/Downloadschmod +x jdk-6u22-linux-i586.bin./jdk-6u22-linux-i586.bin

You'll see all the files extract, and you'll wind up with a jdk1.6.0_22 directory (or perhaps something different based on the version you downloaded). Personally I like to have Java in my /opt directory, so if you want to follow suit, type the following in your terminal (again hitting enter after each line): sudo mkdir /opt/javasudo mv jdk1.6.0_22 /opt/java

ADD JAVA ENVIRONMENT VARIABLES TO .bashrc

With Java in place, I like to set a couple of variables in .bashrc to make Java and Java applications a bit easier to work with. Navigate to your home directory (cd ~/) and open up .bashrc in vi or your favorite editor. Note that if you're new to GNU/Linux, the . before the file means it's hidden, so you won't see it in a plain old ls, but of course ls -a will show it.

With .bashrc open, scroll down to below the HISTSIZE and HISTFILESIZE lines (at least that's where I put this stuff), and you're going to add the following lines:PATH=${PATH}:/opt/java/jdk1.6.0_22/bin export PATHJAVA_HOME=/opt/java/jdk1.6.0_22export JAVA_HOME

Save the file, and then you'll have to log out of your terminal and log back in for these settings to take effect. Type exit and then hit enter to close your terminal, and then re-open the terminal. To make sure your settings took, type the following in your terminal, hitting enter after each line:echo $PATHecho $JAVA_HOME

You should see the Java directory included in your path, as well as see it for the value of JAVA_HOME.

Note that by editing .bashrc the changes only affect your user. If you want these settings available to all users, you'll be editing /etc/profile instead.

DOWNLOAD/INSTALL TOMCATWith Java in place, let's grab Tomcat. You can of course substitute a different JEE server or servlet container if you're so inclined, but if you do you're on your own for the setup. ;-)

On the left-hand side under "Download" click on the latest version, which is currently Tomcat 7. (Note that Tomcat 7 is still technically in beta if you care about such things.)

On the download page, scroll down a bit and under "Core" click on the .tar.gz link.

After the file downloads (again assuming you have downloads go to your Downloads directory), in your terminal do the following (hit enter after each line): cd ~/Downloadstar -xvf apache-tomcat-7.0.2.tar.gz

You'll see the files extract, and at the end of that process you'll have an apache-tomcat-7.0.2 directory in your Downloads directory. I prefer to have that in my home directory on my dev boxes, so type this in your terminal and hit enter (assuming you're still in your Downloads directory): mv apache-tomcat-7.0.2 ../

Next to make Tomcat a bit easer to access, we'll add a symlink called tomcat that points to the real Tomcat directory. More terminal stuff:cd ../ln -s apache-tomcat-7.0.2 tomcat

With all that in place you can now access the Tomcat directory structure via ~/tomcat which I find pretty handy.

CONFIGURE TOMCATNext we need to configure Tomcat a bit, so in your favorite text editor, create a setenv.sh file in Tomcat's bin directory. If you want to do this in your terminal with vi, type the following:cd ~/tomcat/binvi setenv.sh

What we'll be adding to this file is some settings that Tomcat will use when it starts up. Depending on your machine and/or preferences you may want to adjust the memory settings, but if you aren't sure what this stuff does, these are decent generic settings and you can always change them later.
Add these two lines to setenv.sh and then save the file:export JAVA_HOME=/opt/java/jdk1.6.0_22export CATALINA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=384m"

Again if you know what you're doing here, feel free to change your memory settings accordingly.
You should now be able to fire up Tomcat without any errors, so navigate to ~/tomcat/bin in your terminal and type ./startup.sh

You'll see a few lines spit out to the terminal, and if you don't see errors, open up a browser and go to http://localhost:8080 If you see the Tomcat welcome screen you're good to go.

Note that I won't be covering additional Tomcat configuration here, particularly hooking it into Apache, because there are a ton of other howtos and blog posts about that very topic. If you have specific questions in this area I'm happy to help, so comment below and I'll either comment or write another blog post as necessary.

ADDITIONAL CONFIGURATIONThere's one additional bit of configuration I tend to do because particularly on a dev box, you'll run into a problem with this sooner or later if you abuse your machine like I do.

In a terminal (you and your terminal are friends by now, right?), or using your favorite text editor, you're going to edit /etc/security/limits.conf to increase the maximum number of files your user can have open. Open that file and add the following lines to the bottom of the file:yourusername soft nofile 10000yourusername hard nofile 10000

DOWNLOAD AND INSTALL SPRINGSOURCE TOOL SUITE/ECLIPSEUnless you already have a favorite Java IDE, much as it's not in fashion to say so I'm a big fan of Eclipse. I personally have been using SpringSource Tool Suite (STS) for quite a while now, and it's a great Eclipse-based IDE for Java, Groovy, Grails, and of course CFML development once you throw in CFEclipse.

After downloading the Eclipse or STS of your choice, extract the files and then move them to your home directory (at least that's where I put them). This should be old hat by now--in your terminal do: cd ~/Downloadstar -xvf NAME_OF_FILE_HERE.tar.gzmv NAME_OF_EXTRACTED_DIRECTORY_HERE ../

STS has a bit of a different directory structure since it comes with tcServer and Roo, so you'll actually go into the directory and be moving the STS directory into your home directory. Since it has a long name like springsource-tool-suite-sts-2.3.2-RELEASE or something like that, I tend to move and rename to something shorter, e.g.:mv LONG_DIRECTORY_NAME_HERE ~/sts

Once things are moved, you can go into the directory that you moved to your home directory (which will be either sts or eclipse most likely), and then type either ./STS or ./eclipse to launch the program.

ADD LAUNCHER FOR STS/ECLIPSEAlthough you can certainly start STS or Eclipse from the terminal if you like, most people tend to like to have a pretty button to click on to launch the program. The bad news is you have to add this yourself. The good news is it's very easy.

Right click on the Ubuntu logo in the top left of the screen, and click on "Edit Menus."

Click on "Programming," and then click on "New Item" on the right-hand side of the window.

Leave the type drop-down set to "Application"

For "Name" type whatever you want the name to be (e.g. Eclipse, SpringSource Tool Suite, whatever)

For "Command" you need to tell the launcher not only where the executable is, but also where to find Java. So assuming your executable is ~/eclipse/eclipse you'd enter the following in the Command box: /home/yourusername/eclipse/eclipse -vm /opt/java/jdk1.6.0_22/bin

You can leave the "Comment" box blank, but if you enter something here it's what will show up when you mouse over the icon for the application.

Click on the "spring"-looking icon in the left-hand side of the Create Launcher box and you can choose an icon. Note that they're kind of in a weird format. STS comes with its own icon so you can navigate to the STS directory and select the icon.xpm file. If you're using Eclipse you can search for 'eclipse icon launcher ubuntu' on the interwebs and find stuff you can use.

Click OK and your launcher will be added to the Programming menu when you click on Applications in the top left of the screen.

INSTALL CFECLIPSE

If you're a CFML developer you likely already know how to install CFEclipse and since Eclipse is Java based it's the same on every platform. If you're not familiar with installing CFEclipse, head on over to the web site and you'll find great instructions.

That's pretty much it! You're now a hard-core Java/CFML developer on GNU/Linux, other than all that pesky Tomcat/Apache configuration of course. As I said earlier if you need help with that, comment below and I'll do my best.

Popular posts from this blog

This is a first for me since under normal circumstances we run all our Django applications on Linux with Nginx, but we're in the process of developing an application for another department and due to the requirements around this project, we'll be handing the code off to them to deploy. They don't have any experience with Linux or web servers other than IIS, so I recently took up the challenge of figuring out how to run Django applications on Windows Server 2012 with IIS.

Based on the dated or complete lack of information around this I'm assuming it's not something that's very common in the wild, so I thought I'd share what I came up with in case others need to do this.

If you follow me on Google+ you'll know I had a recent rant about Windows Media Center, which after running fine for about a year suddenly decided as of January 29 it was done downloading the program guide and by extension was therefore done recording any TV shows.

I'll spare you more ranting and simply say that none of the suggestions I got (which I appreciate!) worked, and rather than spending more time figuring out why, I decided to try something different.

NextPVR is an awesome free (as in beer, not as in freedom unfortunately ...) PVR application for Windows that with a little bit of tweaking handily replaced Windows Media Center. It can even download guide data, which is apparently something WMC no longer feels like doing.

Background
I wound up going down this road in a rather circuitous way. My initial goal for the weekend project was to get Raspbmc running on one of my Raspberry Pis. The latest version of XBMC has PVR functionality so I was anxious to try that out as a …

My setup for my day job these days is a Surface Pro 4 and either an LG 34UC87M-B or a Dell P2715Q monitor, depending on where I'm working. This is a fantastic setup, but some applications have trouble dealing with the high pixel density and don't scale appropriately.
One case in point is Skype for Business. For some reason it scales correctly as I move between the Surface screen and the external monitor when I use the Dell, but on the LG monitor Skype is either massive on the external monitor, or tiny on the Surface screen.
After a big of digging around I came across a solution that worked for me, which is to change a setting in Skype's manifest file (who knew there was one?). On my machine the file is here:
C:\Program Files\Microsoft Office\Office16\LYNC.EXE.MANIFEST
And the setting in question is this:<dpiAware>True/PM</dpiAware>
Which I changed to this:
<dpiAware>False/PM</dpiAware>
Note that you'll probably have to edit the file as administr…