Linux Can’t load library:libmawt.so


Your a Java developer and you’ve installed Linux. Maybe this is your first time converting from Windows. Maybe you’re a Linux veteran trying Java for the first time. Maybe you’re new to both Java and Linux and you’re running some crappy program some other Java guy wrote. Whatever your background is, you now find yourself staring at an unstatisfied link error. You don’t know what angered the link and you have no idea how to satisfy it. Hi, I’m Cliff and you’re here because you suck at satisfying links. But we already knew that, didn’t we? Does the error below look familiar?

java.lang.UnsatisfiedLinkError: Can’t load library: /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/motif21/libmawt.so
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1666)
at java.lang.Runtime.load0(Runtime.java:787)
at java.lang.System.load(System.java:1022)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1767)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1684)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:67)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:47)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.loadLibraries(Toolkit.java:1610)
at java.awt.Toolkit.(Toolkit.java:1632)

The long answer begins, “four score and seventeen (…seven? …several?) years ago…” and continues with babbling about openjdk and motif libs with a bunch of other nonsense you probably don’t particularly care about. The short story (which is also why you’re here listening to the most long-winded developer this side of the east coast that loves to insert rambling between parenthesis as if that makes any of his blog posts easier on the eyes…) is that you probably need to unset or set an environment variable. “export AWT_TOOLKIT=MToolkit” will cause the error while “export AWT_TOOLKIT=XToolkit” should make it go away. The environment variable controls which one of Linux’s windowing toolkits are used to draw the program on your screen. The MToolkit causes the Java program to look for the “libmawt.so” file which is a Motif Abstract Windowing Toolkit Shared Object, hence the “m-a-w-t.s-o” in the file name. Shared objects are the Linux way of sharing code. Other operating systems use other files. Windows uses “.dll” files, while Mac OSX uses “dylib” files. The Abstract Windowing Toolkit is the Java way of drawing programs on your screen which is abstract so that it can change the way the program looks and feels. Motif is one of the many looks of a java program, while others include “Native”, “Metal”, “Aqua” and others. Not all of these looks are available in each distribution of Java so chances are that you copied a program from a system (or developed a program for a system) that included the Motif look and feel and now you’re trying to run it on your fresh Linux install.

The good news is the problem is easy to fix once you know the how and why. The bad news is you’ll probably do something clever like putting “AWT_TOOLKIT=XToolkit” in your “~/.bash_profile” and forget this hack is in place which will likely cause other issues several months down the line when you want to toy with Compiz-Fusion but your IntelliJ editor is acting funny, locking up or going completely dark or something. That’s your good-news/bad-news for the day. Happy coding and clever hacking to you all.

3 Comments

  1. YUI

    You should use Solaris to run java smoothly :D

  2. Interesting… does the Solaris version of KDE run better than the other Linux versions? I’ve had nothing but trouble in a few areas with KDE 3.x. For one the Java issue is a constant pain, not being able to type in text fields due to some undiagnosed windowing bug. The other issue I have is the SAMBA configuration in Control Center. I doesn’t work. It never worked. I wonder if moving to Solaris would allow me to exchange this headache for a fresh ache somewhere else in my anatomy.

Trackbacks

  1. If your code’s reusable why can’t you use it? « Can’t see nothing but the source code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 250 other followers

%d bloggers like this: