Forum > General

Java application := fpc application !

(1/2) > >>

Fred vS:
There is a hypra-simple way to convert all your fpc applications into Java applications !

It is working for all fpc console-applications.

Here how to do (using the fpGUI demo /fpGUI/examples/gui/filedialog.lpr).

The original fpc program:
1) Change:

--- Code: --- program filedialog;
 {$mode objfpc}{$H+}
--- End code ---
into =>

--- Code: ---library filedialog;
{$mode objfpc}

--- End code ---

2) Change:

--- Code: ---procedure MainProc;
--- End code ---
into =>

--- Code: ---procedure MainProc(PEnv: pointer; Obj: pointer); cdecl;
--- End code ---

3) At end, add:

--- Code: ---exports
MainProc name 'Java_filedialog_mainproc';
--- End code ---

=> compile that new fpc library.

The Java application.

--- Code: ---public class filedialog {
public static native void mainproc();
public static void main(String[] args)
--- End code ---

Save it as in same directory.

And to run the Java application, do, in terminal :

--- Quote --- java -Djava.library.path=. filedialog
--- End quote ---

And... IT WORKS ;-) see that :=>



Yes, it's called JNI and we have some docs about it:

Fred vS:

--- Quote ---Yes, it's called JNI
--- End quote ---

Are you sure?  Do you have noticed that it uses one and only one procedure to run all the (complicated) fpc application, without jni.pas in uses section?  :-X

Here sources + binaries (original program and library-Java-compatible) of filedialog fpGUI demo.
The binaries are compiled on Linux 64 bit.

Excellent stuff!!  :) Keep up the good work.

I'll be trying it out this weekend.


--- Quote from: Fred vS on September 16, 2014, 08:22:57 pm ---Are you sure?
--- End quote ---

Yes, I am sure. Your requisite is very simple (just run 1 parameterless procedure), so that's why you can get away with using Pointer instead of the types in jni.pas. If you wanted more java functionality (like sending data back and forth) then you would need the full jni.pas unit.

Anyway, what is the use for this? If you don't need anything from Java anyway I don't see the point.


[0] Message Index

[#] Next page

Go to full version