Cocoa-Java and Jar Frameworks

Note: Didn’t have time to really write this article up – maybe some time I will – but I’m posting it here just in case it comes in handy for someone.

Now that I’m finished with coursework, and just awaiting my exams to start on Wednesday (can’t wait!) – I’ve got a chance to work on a little application I’ve been meaning to write for the last year or so. I’ve just never had the opportunity to get on with it.

Most of this year, I’ve been learning to develop Java applications using Swing. However, the application I’m developing is for the Mac only. I want to be using the Cocoa-Java bridge for the time being as I can’t find an RSS parsing framework as nice as Rome, which is written in Java.

So, I want to include the .jar file that holds the Rome framework in my Xcode application. This assumes you have a Cocoa-Java application set-up in Xcode.

  1. Project > Add To Project
  2. Select the file
  3. New Build Phase
  4. Select Executable
  5. Drag jar to new build phase.
  6. Project > Edit Active Target
  7. Cocoa Java Specific
  8. Change Root Directory to ‘Contents’
  9. Change app.jar to Resources/Java/app.jar
  10. Add desired Jar file by adding MacOS/rome.jar
2006-07-20 [, , , ]
View Comments

Using Tomcat Ant tasks

I’m now really loving Ant for compiling my Java projects together. It really has solved the problem of figuring out what to update, or going through countless commands to compile each package etc.

You could be wondering why I don’t just use a fancy IDE, like Eclipse to do all this for me? Well… I’ve tried. But… I just can’t ‘like’ Eclipse. I admit, I was very impressed with it – tons of functionallity, but in the end, I just couldn’t give up using the beautiful TextMate. Eclipse felt cluttered and I was claustrophobic using it.

Pathetic excuse I know, but I need something I can get on and work with.

(more…)

2006-03-21 [, , ]
View Comments

Tomcat on Mac OS X Tiger

Download the ‘Core’ .tar.gz version of Tomcat (as of this writing 5.5.15) from http://tomcat.apache.org/download-55.cgi. Extract and move the folder:

sudo mv ~/Desktop/apache-tomcat-5.5.15 /usr/local/

That’s all you need to do to actually install Tomcat–nice and simple. Now to create some start and stop scripts…

cd /usr/local/bin
sudo nano start_tomcat

Enter the following and save:

#!/bin/sh
export CATALINA_HOME=/usr/local/apache-tomcat-5.5.15
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
$CATALINA_HOME/bin/startup.sh

Now a stop script:

sudo nano stop_tomcat

Enter the following:

#!/bin/sh
export CATALINA_HOME=/usr/local/apache-tomcat-5.5.15
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
$CATALINA_HOME/bin/shutdown.sh

Voila! Now to start Tomcat, use /usr/local/bin/start_tomcat and to stop it use /usr/local/bin/stop_tomcat.

If you have /usr/local/bin included in your PATH environment variable, then you can start and stop Tomcat using start_tomcat and stop_tomcat respectively straight from the Terminal.

When Tomcat is started, you can see the installation by going to http://localhost:8080/. In order to manage Tomcat, you’ll need to modify the tomcat-users.xml file.

cd /usr/local/apache-tomcat-5.5.15/conf
sudo nano tomcat-users.xml

Inside this file, modify it so it includes the following tags:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="davidwinter" password="123" roles="admin,manager"/>
</tomcat-users>

Where davidwinter is the username you want to use, and 123 being the password you desire.

You can then manage your Tomcat applications using this link; http://localhost:8080/manager/html.

2006-02-20 [, , , ]
View Comments

Mac friendly Java apps in a few lines

Mac menu-bar? Set this before you initiate your JFrame in your main class:

System.setProperty("apple.laf.useScreenMenuBar", "true");

Other systems will just ignore this and the menu-bar will appear as normal for that system.

Command keyboard button as default for keyboard shortcuts?

yourJMenuItemObject.setAccelerator(
    KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_O,
        Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

This will get the default key for the operating system the Java app is running on. So that means ‘Control’ for Windows and ‘Command’ for Mac.

With those small things, you can make a Java app feel like a true part of the Mac family without sacrificing it working on other systems or the need for a separate binary.

2006-02-18 [, ]
View Comments

Sorting a Vector using Collections.sort()

Collections.sort() allows you to sort a Collections framework that is inherited from the List class. The Vector class is, so that’s great!

(more…)

2005-12-08 [, ]
View Comments

Java foreach loop

Coming from a PHP background, it’s always annoyed me that I can’t use something as simple as a foreach() loop in my C++/Java applications.

(more…)