13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

136Chapter 5The Sun Microsystems Java Software <str<strong>on</strong>g>Development</str<strong>on</strong>g> Kitthese libraries is built and maintained with the ldc<strong>on</strong>fig program. The libraryloader in the JVM, however, works as the shared library system in Solaris, wherethe LD_LIBRARY_PATH is searched for shared libraries. If you try a JNI methodand get library errors, check your LD_LIBRARY_PATH first. Here, we used “.”,meaning “current directory.” In practice, you wouldn’t do this. You would deployyour shared library to a standard locati<strong>on</strong> and have LD_LIBRARY_PATHpreset to that directory or directories. We just wanted to show you how itworks here.Let’s see our class in acti<strong>on</strong> now.$ java GetUsermschwarz$ suPassword:# export LD_LIBRARY_PATH=.# java GetUserroot# exitexit$To JNI or Not to JNIWe dislike religious debates. We have no desire to nail down what taintsthe purity of Java and what does not. A warning we do want to give youis, if you are an experienced UNIX C/C++ developer, you must resist thetemptati<strong>on</strong> to use JNI and native methods all over the place. The JavaAPIs are extensive, and there are probably classes that already do whatyou want to do. You will be tempted to use native methods because “youknow how to do it in C.” Resist. Find the Java way. JNI is a great way tointroduce subtle and hard to find bugs into your Java programs. Leavethat to the API and JVM coders. ;-)That said, we d<strong>on</strong>’t want to discourage you from making use of JNIwhen it is the right way, or the <strong>on</strong>ly way, for what you need to do. Thetool is there. Use it. Just remember what it does cost you in portabilityand what it may cost you in maintenance and debugging. Designdecisi<strong>on</strong>s have costs and benefits. Try to find the balance.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!