Tuesday, January 31, 2012

Terminal Unmounting

I'm reducing the amount of clicking I do when using my computer. To that purpose, I wanted to learn how to unmount/eject media, either virtual or physical, from the command line instead of having to simulate a right-click by pressing the Ctrl button _ aiming the trackpad to the volume's icon, after having had to find it on the desktop.

So I learned. Simple:
sudo umount /Volumes/Name

and if it's stubborn,
sudo -f umount /Volumes/Name

and if it's stubborner,
sudo diskutil umount force /Volumes/FooBar

Credits:
http://loopkid.net/articles/2008/06/27/force-unmount-on-mac-os-x

p.s: On the same clicking-reduction line, the terminal command "open" will open any file or directory, just as it would by double-clicking on it through the GUI. Yay.

Monday, January 30, 2012

Command line Java NoClassDefFoundError


So I was having trouble with Java. Eclipse worked perfectly, but when I wanted to compile/run from the command line, I always got this:

Exception in thread "main" java.lang.NoClassDefFoundError: Adder/class
Caused by: java.lang.ClassNotFoundException: Adder.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)


So I looked up the error, and found this nice post:
http://www.codegravity.com/blog/noclassdeffounderror

The solution is to include the current path (.) in the classpath, such as:

java -classpath . Adder (Adder is the name of the class).
Tha's it.

Attaching JDK Source Code

So I installed Eclipse on my Mac OS X 10.7 Lion, and everything was working peachy, except I can't see the core JRE source code :(. Can't go into String's or Integer's source code, criticize Sun source code, or figure out what some obscure but potentially useful classes actually do.

So it's not critical. But it's annoying. So today I looked it up, and I think I found the solution. Credit to
https://developer.apple.com/downloads/index.action

and shame on Apple for being so annoying so often.

And in case of broken link, the pasted steps are here:



  • Go to http://connect.apple.com and download Java for Mac OS X 10.6 Update 3 Developer Package




  • Install it.




  • Open a Terminal.app window




  • sudo -s




  • cd /System/Library/Frameworks/JavaVM.framework/Home




  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/src.jar .




  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/docs.jar .




  • Replace for your current versions, of course.

    Hadoop Setup

    So I gotta install Hadoop on my Mac OS X 10.7 Lion, and I start running into some errors. I'm following the official setup tutorial: http://hadoop.apache.org/common/docs/current/single_node_setup.html. To avoid these, do the following:

    • Modify hadoop-x.x.x/conf/hadoop-env.sh with these lines:
    export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    export HADOOP_OPTS="-Djava.security.krb5.realm=OX.AC.UK -Djava.security.krb5.kdc=kdc0.ox.ac.uk:kdc1.ox.ac.uk"

    The first line allows things to run. The second avoids the weird runtime warning
    "Unable to load realm info from SCDynamicStore".
    • Enable ssh to localhost for pseudo-distributed operation:
    Go to System Preferences -> Sharing -> Remote Login -> check little checkbox.

    That's it. Just follow the rest of the instructions and you'll be set up good :).