JAVA与COBOL相互调用

来源:互联网 发布:手机自动打开软件 编辑:程序博客网 时间:2024/05/29 19:59
Setting Up the Environment for Java and COBOLYou need a Java run-time system on any machine which is going to execute Java applications. If you are going to develop mixed Java and COBOL applications, you will also need a Java development environment. You can use either the Java Software Development Kit available from Sun, or any Java IDE which is based on either the Sun or Microsoft run-time environments listed below.Net Express currently supports the following Java run-time systems on Windows:The Sun Java SDK 1.2.2 or 1.3 (this is for development) The Sun Java Runtime Environment 1.2.2 or 1.3 or 1.4 (this is a distributable run-time environment you can use for shipping applications) Before you start writing COBOL and Java programs which interact, you need to set up the following environment variables for the COBOL and Java run-time systems:COBJVM If you have COBOL programs which are going to call Java, you must tell the COBOL run-time system which Java run-time system you are using. To do this, set environment variable COBJVM to one of the following:SUN (for the Sun run-time system). For example:set cobjvm=SUN PATH In addition, if you are using the Sun Java run-time system, add the subdirectory containing the jvm.dll file to your system path. The location of this file depends on which version of the Java Development Kit (JDK) you are using. For example:set path=%path%;c:/jdk1.3.1/jre/bin/subdirectory Where subdirectory might be client, classic, hotspot or server.This environment variable enables the COBOL run-time system to locate the jvm.dll file contained in this directory. Do not move jvm.dll to a different location, because it has dependencies on other files shipped as part of the Sun Java run-time system. CLASSPATH If you have Java programs which are going to call COBOL, you need to provide some Java classes which interface to the COBOL run-time system. To do this, ensure that mfcobol.jar is specified by the CLASSPATH environment variable for your Java run-time system. You should also ensure that CLASSPATH specifies the current directory, denoted by a period (.). For example:set classpath=%classpath%;.;c:/program files/Micro Focus/net express/base/bin/mfcobol.jarYou can also set the Java class path when you run a Java program, using the -classpath switch. For example:java -classpath ".;c:/program files/Micro Focus/net express/base/bin/mfcobol.jar;%CLASSPATH%" MyClass Compiling COBOL Programs that Call JavaAny COBOL program which is going to call Java must be compiled with the following directive:ooctrl(+p-f)This does two things:Adds type information to invoke statements, which the COBOL run-time system needs to convert data correctly between the COBOL and Java domains Prevents the compiler from folding method names it invokes to lower-case - Java method names are case-sensitive Compiling COBOL Programs that are used from the CobolBean interfaceAny COBOL program which is going to be called from Java using CobolBean.cobcall*() methods methods should be compiled with the DATA-CONTEXT compiler directive. This enables the runtime system to create new application storage areas for each instance of a CobolBean that is created.Compiling Java Programs in Net ExpressWhen you use the Net Express IDE to create OO COBOL classes for use with Java, the Class Wizard adds the Java wrapper classes for OO COBOL to your Net Express project. The Java classes are compiled by the IDE when you rebuild your project. To set up this support edit mfj.cfg, in your net express/base/bin directory, to contain the full path and filename of your Java compiler.If your net express/base/bin directory does not contain a copy of mfj.cfg, you will need to create it. Net Express creates mfj.cfg file the first time you compile a Java program in the Net Express IDE, providing that it can find the location of a Java compiler in your PC's registry or on the PATH environment variable.In addition to specifying the Java compiler to use, you can use mfj.cfg to specify any Java compiler command line arguments. If you edited mfj.cfg to contain the following:d:/jdk/bin/javac.exe -verboseevery time you compiled a Java program from the Net Express IDE, Net Express would use javac.exe in the d:/jdk/bin directory, specifying the -verbose option.Linking to the Multi-threaded Run-time SystemAll COBOL programs for use with Java must be linked with the multi-threaded run-time system.On Net Express, click Multi-threaded on the Link tab of the Project Build Settings dialog box. If you are debugging programs, click Settings on the Animate menu, and check Use multi-threaded runtime.Unsupported JVM ErrorsWhen you call COBOL from Java, the OO COBOL Java support loads one of several cbljvm_*.dll modules to interface to the Java Virtual Machine (JVM). The exact file loaded depends on the JVM you are using, and is selected by querying the name of the JVM the Java program is running under.If your JVM is not one of those listed as supported, you will get a fatal "Unsupported JVM" error. You can force the loading of a particular JVM by setting a Java system property, called com.microfocus.cobol.cobjvm, to the name of one of the supported JVMs. For example, to load the support for the Sun JVM, contained in cbljvm_sun.dll, set this property to "sun".You can set this property on the command line that runs your Java program, as follows:java -Dcom.microfocus.cobol.cobjvm=name class where name is the name of the support module you want to use. For example, to run Java program myclass with the support for the Sun JVM:java -Dcom.microfocus.cobol.cobjvm=sun myclassIf you get the "unsupported JVM" error, try the Sun JVM first as many JVMs are rebadged from Sun.
原创粉丝点击