|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
General Java JAVA Technology on the Linux Platform
JAVA Technology on the Linux Platform
By: Calvin Austin
Dec. 1, 2000 12:00 AM
The Java 2 Platform, Standard Edition (J2SE technology) v1.3 for Linux means that Linux users and developers can take advantage of thousands of Java technology-based applications, from enterprise e-commerce infrastructure to client-side applications. It also opens up a huge emerging market for companies that already develop Java products. The Java 2 Platform port was developed with the assistance of the blackdown.org porting group. Although Linux is a UNIX-based operating system, it's evolved at a different pace and direction than other UNIX platforms, making a port of the Java platform a sizable challenge. Many important bug fixes have gone into the Linux operating system and associated GNU libraries as a result of the work initiated by Blackdown, not just on Intel-based distributions but also Power PC and Sparc platforms. In particular, the linuxthreads library has improved dramatically over the past year on multiprocessor machines. In an ideal world, the Java 2 Platform, combined with Java development tools such as Forté Community Edition, should be all you need to develop your projects. However, if the Linux operating system is a new development environment for you and you've previously developed with the Java 2 Platform for Windows or Solaris, you might find Linux a little different. This article provides tips to bring you up to speed as quickly as possible developing on the Linux platform.
SDK and JRE Installation Tips rpm -i --badreloc --relocate /usr/java/=/usr/local/home j2sdk-1_3_0-linux.rpm After relocating the files as shown above, start developing by adding the bin directory from the SDK or JRE installation to your $PATH. For example, using the bash shell, the $PATH is updated:
export PATH=/usr/java/jdk1.3/bin:$PATH To verify that you've configured your environment, run the java -version command, and you should see a version string confirming that you've installed the Java 2 Runtime Environment:
java -version
Java Plug-in Installation Tips To let your Netscape browser know where the Java plug-in library is, set the NPX_PLUGIN_PATH environment variable to point to the directory where the javaplugin.so shared library is located: export NPX_PLUGIN_PATH=/usr/java/jdk1.3/jre/plugin/i386 To configure the Java plug-in properties, use the ControlPanel program located in the jre/bin directory. In the example above, the program is /usr/java/jdk1.3/jre/bin/ControlPanel.
Java HotSpot Virtual Machine By default the client compiler is enabled, but for intense server-side applications, the server compiler can be run using the -server runtime option. The Java HotSpot Virtual machine normally runs in a mixed mode, as seen in the version output. This means HotSpot will dynamically compile Java bytecodes into native code when a number of criteria have been met, including how many times the method has been run through the interpreter. The mixed runtime mode normally results in the best performance.
About Linux Threads In J2SE Release 1.3, the HotSpot virtual machine uses Linux system threads to implement JavaThreads. Because LinuxThreads are implemented as a cloned process, each JavaThread shows up in the process table if you run the ps command. Although this may look different, it's normal behavior for threaded programs on Linux:
java -jar Notepad.jar In Table 1, the process id 11712 is the invoked JVM. The other processes with id 11712 as the parent process (listed under the PPID column) are JavaThreads implemented by the Linux system threads library. Each LinuxThread is created as a process clone operation that leaves the task of scheduling threads to the process scheduler. On Solaris, however, JavaThreads are mapped onto user threads, which in turn are run on lightweight processes (LWP). On Windows the threads are created inside the process itself. Today, creating a large number of JavaThreads on Solaris and Windows is faster than on Linux. Thus, you might need to adjust programs that rely on platform-specific timing to take a little longer on startup when they run on Linux.
Linux Debugging Tools
Using GDB gdb /usr/java/jdk1.3/bin/i386/native_threads/java 11712 The output from using the gdb tool should look similar to Listing 1. At this point the gdb tool has connected to the running Java process and is waiting for user input. With gdb attached to the JVM, you can run any gdb commands. If you've used gdb before, these commands will look familiar. The info threads command lists the LinuxThreads, the t 12 command selects thread number 12 as the current thread, and the where command lists the stack frames in that thread (thread number 12, in this example). The output from an example session is shown in Listing 2.
Starting a Java Virtual Machine using gdb To enable the JVM to run from inside gdb on Linux, the following setup needs to be in place:
Generating a Java stack trace on Linux
The resulting stack trace is a snapshot of the JavaThreads and details the state of each thread. In each thread trace, a value called nid - the hex number of the cloned process it came from - can be used to track down deadlocks or busy sections in your application. For more details on analyzing Java stack traces, refer to the "Debugging Applets, Applications, and Servlets" chapter in Advanced Programming for the Java 2 Platform (Addison-Wesley, 2000).
Integrating Native JNI Code on Linux
To recompile your native C or C++ code and generate the native library file, use the GNU tool gcc for C programs and g++ for C++ programs, and supply the options as shown in the next example. Finally, set the LD_LIBRARY_PATH environment variable to point to the directory where the final native library is located. In the following examples the native library is called libnativelib.so and is loaded from within a Java program by the using System.loadLibrary("nativelib").
GNU C/Linux
GNU C++/Linux
Desktop Differences (Copy and Paste)
Linux uses a mouse-driven copy-and-paste mechanism in which mouse button one selects and copies text, and mouse button two pastes the text. This technique works for Abstract Window Toolkit (AWT) components because they use the primary selection to achieve copy and paste. Project Swing components, however, use the system clipboard for copy and paste, and most tools on the desktop, apart from the Netscape browser, don't use the clipboard.
A workaround to this limitation is to map a key or mouse button to access the system clipboard:
The lines above can be passed as a value to an X tool using the -xrm option. Alternatively, the mapping can be made accessible to the entire desktop by including it in the .Xdefaults file in the user's home directory. The command xrdb -merge $HOME/.Xdefaults will reload updates in the .Xdefaults file.
Conclusion
In addition, the amount of Linux knowledge needed to develop or deploy Java applications is relatively small, making Linux an attractive choice as a development platform.
Resources Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
|
||||||||||||||||||||||||||||||||||||||||||||||||