[Deutsch] | [Bottom of Page] | [MN Home Page] | [MN Watcom Page] |
The following is a step-by-step description to create a Dynamic Link Library (DLL) for the Java Native Interface (JNI) using Watcom. It refers to the 'Hello World!' sample from Sun Microsystems Java Tutorial. To follow the steps beginning with 'Create a Shared Library' it is nesseccary to:
All files mentioned are available as a ZIP-Archive you can dowload (You have to change the JDK path in the makefile to fit with your system). The sample was created and tested with the following configurations:
Operating System: | OS/2 Warp 4 (R9.023) and Windows 95 (OSR 2.1) |
Compiler: | Watcom 11.0b |
JDK: | 1.1.6 (OS/2, IBM) and 1.2.1 (Win32, Sun) |
IMPORTANT NOTE
This description assumes that you are familiar with creating DLLs and
with makefiles for the operating system or at least that you have
an idea what this is all about. A corrupt DLL may hang your system what
may result in loss of data. You follow this description at your own
risk.
Step 1: Adjust a JDK Header File (OS/2 only)
Search for the file 'jni_md.h
' in the directory
inlude\os2
of your JDK installation, open it and
go to the following lines:
#if defined OS2 /*ibm*/ #define JNIEXPORT #define JNICALL0 _System #ifndef JAVA_EXE // :CHANGED: mn 20000405: #define JNICALL _Export JNICALL0 #define JNICALL __export JNICALL0 // ... more
This lines define highly compiler dependend keywords. Out-of-the-box
you'll find keywords for IBM Visual Age for C++. At first
_System
for functions that use the OS/2 32bit API and
next _Export
for the DLL functions that should be
accessible from out of the DLL. For Watcom you have to change
_Export
to __export
.
Step 2: Select Compiler and Linker Options
To build the DLL easily it's a good idea to create a makefile and a
linker directive file (.lnk file). The makefile should contain the
following:
hello.dll : HelloWorldImp.obj wlink @hello HelloWorldImp.obj : HelloWorldImp.c wcc386 $< -i=$(%WATCOM)\h;$(%WATCOM)\h\$(OS);$(%JAVA)\include;& $(%JAVA)\include\$(OS) -bd -6s
The important options are -bd
to create a DLL and
-6s
to compile with Stack Calling (otherwise the
compiler will append an underscore to the method name and the
JVM will therefore not recognize the method).
The .lnk file should contain the following:
system os2v2 dll initinstance # OS/2 system nt_dll initinstance # NT file HelloWorldImp.obj name hello option manyautodata # OS/2 only option caseexact segment type data nonshared segment type code shared reference __DLLstart_
Beside the options you'll find in the JDK help important options
are option caseexact
and
reference __DLLstart_
. The first ist neccessary
because Watcom exports function names all uppercase by default but
the JVM will load mixed case. The second option will create an
entry point for the DLL. Please read the Watcom online-help for
details about each option.
Step 3: Create and Test the DLL
Enter the command wmake
at a command line to process
the makefile and create the DLL. The result is the needed DLL and
the command 'java HelloWorld
' should display
'Hello World!
' at the command line.
Credits:
The following people gave me important hints and help:
Thank you.
[Content] | [Top of Introduction] |
The following is a step-by-step introduction to enable JavaTM
syntax highlighting for the WatcomTM Windows® NT Editor
(%WATCOM%\BINNT\VIW.EXE
, where %WATCOM%
is the
directory you installed the WatcomTM software). This only
works with version 11.0b and contains three steps:
Please read the 'Known problems' section and report new problems or better solutions to the Watcom newsgroup.
IMPORTANT NOTE
This is unsupported and undocumented and comes to you with
absolutely no warranty. After you made the modifications
test the editor with various files and see if it works. If
it doesn't work: Undo the modifications with the backup that
was made during this introduction.
Step 1: Provide the keywords
As Stephen Howe from TeamSybase guessed the files that hold the
keywords can be found in %WATCOM%\EDDAT
. When you search
for .dat
files you found the following (and some more):
c.dat | - C keywords |
cpp.dat | - C++ keywords |
fortran.dat | - Fortran keywords |
Now you have to create a file that holds the JavaTM
keywords (Or just click on the link below). Don't forget to insert
the number of keywords in this file in the first line of the
file.
Example:
59
abstract
boolean
break
...
Save these list in a file named '
java.dat
' in the directory
%WATCOM%\EDDAT
.
(Note: With Netscape® Navigator® you may have to hold down the
[SHIFT]-Key to download the file)
Step 2: Customize the options and colors
Start VIW and in the menu goto
Options -> File specific ...
In the textfield 'File Type:' enter '*.java' and click on
the 'Insert' button. The new extension is now added to the
list.
Change the options you like to change and don't forget to
enable syntax highlighting because that's what we're doing
here :-)
Hints:
Click on the 'OK' button to close the dialog box. Leave VIW with
File -> Exit
Step 3: Modify the editors initialization file
Copy the file 'weditor.ini
' in your windows directory
to 'weditor.bak
' and open the
'weditor.ini
' with your prefered text editor
(you better DON'T use VIW!). Notepad is a good choice.
Scroll down until you see the following line
filetypesource *.java
Here are the sections where your options are stored.
Example:
If you set the grep extensions you'll see a line
set grepdefault *.java
Now comes the trick. Look at the line
set language 1
Here you select the language for syntax highlighting. But what
is the right digit for JavaTM?
Just look at the other 'filetypesource' sections. Here are the
digits (note the extensions at the beginning of each section!):
Extension | Digit |
---|---|
*.c *.h | 1 |
*.cpp *.hpp *.cc | 2 |
*.for *.f *.inc | 3 |
*.* | 0 |
Select 4 for your JavaTM section, save the initialization
file and start VIW. Open a JavaTM source file and look at
some JavaTM specific keywords (e.g. import
).
If you made everything right it should work now.
ID0001 | |
Reported By: | Markus Neifer |
Reported On: | 05/10/1999 |
Status: | FIXED |
Description: | If you uncheck syntax highlighting or change the language in the 'File Specific Options' dialog box you'll lost the ability for JavaTM syntax highlighting. |
Fix: | Don't worry. Your options aren't lost. You have to edit 'weditor.ini' again. Go to the 'filetypesource *.java' section and reenter the selected digit for JavaTM. When you restart VIW everthing is fine again (or should be :-). |
ID0002 | |
Reported By: | Axel Schmitz-Tewes |
Reported On: | 05/12/1999 |
Status: | FIXED |
Description: |
Make sure you modify the right 'weditor.ini '.
Under Windows® NT you have to change the file in
%systemroot% and not the one in
%WATCOM%\EDDAT .
|
[Content] | [Top of Introduction] |
You could use the Concurrent Versions System GNU CVS together with Watcom. To do so you have to do the following:
CVS.EXE
' can be found within the PATH
statement.
%watcom%\binw\gen_ci.bat
'
(this file is called from the IDE to checkin files) so that it
looks like this:
@echo ********************************************************************** @echo This is %WATCOM%\binw\gen_ci.bat. @echo You can edit this batchfile to provide checkin ( and unlock ) @echo functionality to any generic revision control system. @echo ********************************************************************** @rem From IDE: Name=%1, File Containing Message=%2, Project=%3, Target=%4 cvs -r commit -F %2 %1
%watcom%\binw\gen_co.bat
'
(this file is called from the IDE to checkout files) so that it
looks like this:
@echo ********************************************************************** @echo This is %WATCOM%\binw\gen_co.bat. @echo YOU can edit this batchfile to provide checkout ( and lock ) @echo functionality to any generic revision control system. @echo ********************************************************************** @rem From IDE: pause=%1, name=%2, project=%3, target=%4 @rem Note: This is also called from the Editor, @rem in which case the only parameter is the name (%1) cvs edit %2 if [%1]==[no_pause] goto done pause :done
[Content] |
Using the OS/2 IDE it seems that it's not possible to automatically use relative path names in targets (as it's possible in Windows). The file selector only reports full path names to the 'Add Source' dialog and you have to change everything by hand.
To make that less painful Stefan Schwarzer provides his smart Python tool 'mvsource'. It can automatically change path names in target files. Please try it.
If you don't have Python/2 (Python for OS/2) yet you can download it for free from Jeff Rush's Python Pages.
[Deutsch] | [Top of Page] | [Content] | [MN Home Page] | [MN Watcom Page] |
All product names mentioned on this page and on linked pages are the trademarks or registered trademarks of their respective owners.
Copyright © 2000-2002 by
Markus 'howlingmad' Neifer. All rights reserved.
First released: 01/08/2000
Last updated: 08/17/2002