mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-08 15:52:26 +01:00
Author:halw
Date:2008-12-01T22:45:08.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@112 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -43,58 +43,59 @@ Value of `my_integer' after call to `my_method' is 2
|
||||
===Code description===
|
||||
<code>(Eiffel Code)
|
||||
|
||||
class
|
||||
EIFFEL_TO_JAVA
|
||||
inherit
|
||||
SHARED_JNI_ENVIRONMENT
|
||||
class
|
||||
EIFFEL_TO_JAVA
|
||||
inherit
|
||||
SHARED_JNI_ENVIRONMENT
|
||||
|
||||
create
|
||||
make
|
||||
make
|
||||
|
||||
feature -- Creation
|
||||
feature -- Creation
|
||||
|
||||
make is
|
||||
local
|
||||
class_test: JAVA_CLASS
|
||||
instance_of_class_test: JAVA_OBJECT
|
||||
fid: POINTER
|
||||
value: INTEGER
|
||||
j_args: JAVA_ARGS
|
||||
do
|
||||
--| Creation of the Java object
|
||||
class_test := jni.find_class ("test")
|
||||
create instance_of_class_test.create_instance (class_test, "()V", Void)
|
||||
make
|
||||
local
|
||||
class_test: JAVA_CLASS
|
||||
instance_of_class_test: JAVA_OBJECT
|
||||
fid: POINTER
|
||||
value: INTEGER
|
||||
j_args: JAVA_ARGS
|
||||
do
|
||||
--| Creation of the Java object
|
||||
class_test := jni.find_class ("test")
|
||||
create instance_of_class_test.create_instance (class_test, "()V", Void)
|
||||
|
||||
--| Access to a public attribute
|
||||
fid := instance_of_class_test.field_id ("my_integer", "I")
|
||||
--| Access to a public attribute
|
||||
fid := instance_of_class_test.field_id ("my_integer", "I")
|
||||
|
||||
-- 'fid' contains the id of the field 'my_integer'
|
||||
-- 'value' contains the value of the field referenced
|
||||
-- by 'fid'
|
||||
-- 'fid' contains the id of the field 'my_integer'
|
||||
-- 'value' contains the value of the field referenced
|
||||
-- by 'fid'
|
||||
|
||||
value := instance_of_class_test.integer_attribute (fid)
|
||||
value := instance_of_class_test.integer_attribute (fid)
|
||||
|
||||
--| Access to a static attribute using directly the JAVA_CLASS
|
||||
fid := class_test.field_id ("my_static_integer", "I")
|
||||
value := class_test.integer_attribute (fid) ...
|
||||
|
||||
--| Access to a static attribute using the attribute 'jclass'
|
||||
fid := instance_of_class_test.jclass.field_id ("my_static_integer", "I")
|
||||
value := instance_of_class_test.jclass.integer_attribute (fid)
|
||||
|
||||
--| Access to the method 'my_method'
|
||||
-- Get the id of 'my_method'
|
||||
fid := instance_of_class_test.method_id ("my_method", "(ILjava/lang/String;)V")
|
||||
--| Access to a static attribute using directly the JAVA_CLASS
|
||||
fid := class_test.field_id ("my_static_integer", "I")
|
||||
value := class_test.integer_attribute (fid)
|
||||
|
||||
-- Create the set of arguments for 'my_method'
|
||||
create j_args.make(2)
|
||||
j_args.push_int (2)
|
||||
j_args.push_string("String test")
|
||||
|
||||
-- Create the set of arguments for 'my_method'
|
||||
-- Call to the void method referenced by 'fid'
|
||||
instance_of_class_test.void_method (fid, j_args)
|
||||
end -- make
|
||||
--| Access to a static attribute using the attribute 'jclass'
|
||||
fid := instance_of_class_test.jclass.field_id ("my_static_integer", "I")
|
||||
value := instance_of_class_test.jclass.integer_attribute (fid)
|
||||
|
||||
--| Access to the method 'my_method'
|
||||
-- Get the id of 'my_method'
|
||||
fid := instance_of_class_test.method_id ("my_method", "(ILjava/lang/String;)V")
|
||||
|
||||
-- Create the set of arguments for 'my_method'
|
||||
create j_args.make(2)
|
||||
j_args.push_int (2)
|
||||
j_args.push_string("String test")
|
||||
|
||||
-- Create the set of arguments for 'my_method'
|
||||
-- Call to the void method referenced by 'fid'
|
||||
instance_of_class_test.void_method (fid, j_args)
|
||||
end -- make
|
||||
|
||||
end -- class EIFFEL_TO_JAVA</code>
|
||||
|
||||
|
||||
@@ -10,14 +10,15 @@ The Java interface allows you to call Java routines or attributes from your Eiff
|
||||
===Requirements===
|
||||
* JDK 1.1.8 or newer should be correctly set up (download it at [http://java.sun.com/javase/downloads/index.jsp http://java.sun.com/javase/downloads/index.jsp] )
|
||||
* The environment variable CLASSPATH should defined (check with the JDK documentation on how to do so) and that it contains the Java classes you want to access.
|
||||
* The environment variables should be setup correctly. See $ISE_EIFFEL\library\Eiffel2Java\README.txt for information how to do this..
|
||||
* The environment variables should be setup correctly. See $ISE_EIFFEL\library\Eiffel2Java\README.txt for information how to do this.
|
||||
|
||||
===Borland users===
|
||||
|
||||
On Windows, the JDK includes a set of C libraries which have been compiled for the Microsoft C compiler. Before being able to use the JDK from Eiffel you need to perform the following operation:
|
||||
# In $JDK_HOME\lib, rename javai.lib into javai.lib.microsoft
|
||||
# From the DOS command prompt and in the directory $JDK_HOME\lib, launch the following command <br/>
|
||||
<code>%ISE_EIFFEL%\bcc55\bin\implib javai.lib..\bin\javai.dll</code>
|
||||
<code lang=text>
|
||||
%ISE_EIFFEL%\bcc55\bin\implib javai.lib..\bin\javai.dll</code>
|
||||
|
||||
|
||||
===Limitations===
|
||||
@@ -143,17 +144,21 @@ When you want to call a Java method or access a field, you need to specify its s
|
||||
|}
|
||||
|
||||
The signature for a Java class has the following form:
|
||||
<code>L fully-qualified-class;</code>
|
||||
<code lang=text>
|
||||
L fully-qualified-class;</code>
|
||||
|
||||
For example, class String:
|
||||
<code>Ljava/lang/String;</code>
|
||||
<code lang=text>
|
||||
Ljava/lang/String;</code>
|
||||
|
||||
|
||||
The signature for a method has the following form:
|
||||
<code>(arguments-types) returned-types</code>
|
||||
<code lang=text>
|
||||
(arguments-types) returned-types</code>
|
||||
|
||||
For example, the signature of a method that takes as arguments an integer and a string and return void is:
|
||||
<code>(ILjava/lang/String;)V</code>
|
||||
<code lang=text>
|
||||
(ILjava/lang/String;)V</code>
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user