|
The GNU compiler for Java or GCJ is used for compiling Java source code as native machine code. It is a portable, optimal, ahead-of-time compiler for the Java programming language. It can compile:
Java source code to native machine code
Java source code to Java (class files)
Java bytecode to native machine code
Support for GCJ is included in the low-level API. Developers can use this support for developing native run-time SNMP agents and manager applications.
The packages required for using GCJ are:
com.adventnet.snmp.snmp2
package that contains the low-level APIs.
gcjsnmp2.jar that contains AdventNet's implementation of java.applet.Applet, com.adventnet.snmp.snmp2.SASClient, and other classes. It is to be noted that the class java.applet.Applet is not supported by GCJ. The jar provides a workaround for the Java classes that are not supported by GCJ for compilation. It also includes classes for serializing USM and VACM Tables, which is necessary for SNMPv3 support.
The GCJ compilation library libgcj and the GCJ itself. The libgcj consists of:
The core class libraries
A garbage collector library
An abstraction over the system threads
A bytecode interpreter (optional)
This can be downloaded from http://sourceware.cygnus.com/java
Note that there is no change in the core SNMP APIs because of GCJ support. The only requirement is the additional package (the gcjsnmp2.jar file). The existing snmp2 package can be used for both GCJ and Java applications.
Extracting gcjsnmp2 Package
The gcjsnmp2.jar file has to be manually extracted because the GCJ compiler does not look into jar files for the classes. This can be done using the JDK's jar tool in one of the following ways.
Extract the jar file in the classes directory where the com.adventnet.snmp.snmp2 package resides. The extraction will result in overwriting of the existing SASClient class in the com/adventnet/snmp/snmp2/directory with the new SASClient class in the jar.
Extract the classes in a separate directory. After extraction, the gcjsnmp2 package should be set first in the CLASSPATH followed by the original AdventNet classes. Also, during compilation with GCJ, the new SASClient class in gcjsnmp2.jar has to be given to the compiler instead of the original SASClient in the snmp2 package.
While compiling the AdventNet classes for GCJ, make sure that the following classes are compiled from the gcjsnmp2 package and not from com.adventnet.snmp.snmp2 or JDK package.
com.adventnet.snmp.snmp2.SASClient
java.applet.Applet
This could be done by moving the original SASClient class from the snmp2 directory to a different directory and compiling it.
Environment Setting for GCJ Compilation
There is a file called snmp.properties in the classes/com/adventnet/snmp/snmp2/ directory . This file has to be edited to have the following line.
|
GCJ_COMPILE = 1 |
The default value of this option is 0.
Compiling with the AdventNet SNMP Low-Level API
The following diagram illustrates how the user can develop a native SNMP application using the AdventNet API with the GCJ compiler.
Step I - Create a native library of the AdventNet snmp2 package
The com.adventnet.snmp.snmp2 package along with the gcjsnmp2.jar classes is given to GCJ to get the SNMP2 libraries. Then a shared or a static library archive can be created. The shared library is created by GCJ itself. To create a static library, the classes should be first converted to object files using GCJ. Then a library archive of the object files can be created.
For example, to create a shared library (in Unix-based systems), type the following command.
|
gcj -shared snmp2 classes gcjsnmp2 classes o libsnmp2.so |
The above command creates a shared library file where the snmp2 classes are in the com.adventnet.snmp.snmp2 package and gcjsnmp2 classes are in the extracted gcjsnmp2.jar file.
To create a static library (in Unix-based systems):
Create the object (.o) files.
|
gcj -c snmp2 classes gcjsnmp2 classes |
Create the archive of the object files.
|
ar rv libsnmp2.a *.o |
Create the library.
|
ranlib libsnmp2.a |
Step II - Create the executable of the SNMP application that uses the AdventNet's snmp2 package
The user application could be compiled and linked with the snmp2 library (created in Step I) to produce the native application. For example, the following command creates the native executable called UserExecutable linked with the libsnmp2 library created in Step I.
|
gcj -lsnmp2 user classes or java source files o UserExecutable |
The user classes or Java source files belong to the user's application.
Known Issues in GCJ
GCJ does not work with 2.95.1 release.
This is because of the usage of receive methods in Datagram sockets
inside threads. The application hangs indefinitely inside the receive
call. Also, the library does not have a full implementation of the java.security
package, which is required for SNMPv3.
|
|
Note: The workaround is to use the latest CVS or the latest RPM version of the compiler. |
Latest RPM and CVS versions
of the compiler works only for the NoAuthNoPriv security level in SNMPv3.

The AuthPriv and AuthNoPriv security levels in SNMPv3 version cannot be supported because the libgcj library (from the latest RPM and CVS) does not implement of the MD5 algorithm by default as in JDK. The MD5 algorithm is used for calculating digests of the SNMP messages for these levels. At run time, this throws NoSuchAlgorithmException because of the MD5 algorithm not being found. Also for privacy, the DES encryption is required, which is not available in the library.
|
|
Note: The workaround is downloading the third-party implementation of these algorithms (source), integrating with the libgcj library source, and compiling. There is an implementation of Message Digest and DES encryption from Cryptix, which can be downloaded from http://www.cryptix.org. |
|