Recent

Author Topic: Java application := fpc application !  (Read 4303 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 1675
    • miXimum is the DJ's best friend
Java application := fpc application !
« on: September 16, 2014, 02:49:16 pm »
Hello.
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: [Select]
program filedialog;
 {$mode objfpc}{$H+}
into =>
Code: [Select]
library filedialog;
{$mode objfpc}

2) Change:
Code: [Select]
procedure MainProc;into =>
Code: [Select]
procedure MainProc(PEnv: pointer; Obj: pointer); cdecl;
3) At end, add:
Code: [Select]
exports
MainProc name 'Java_filedialog_mainproc';
end.

=> compile that new fpc library.


The Java application.

Code: [Select]
public class filedialog {
public static native void mainproc();
public static void main(String[] args)
  {
 System.loadLibrary("filedialog");
  mainproc();
 }
 }

Save it as filedialog.java in same directory.

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

Quote
java -Djava.library.path=. filedialog

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

>> https://sites.google.com/site/fiensprototyping/fpgui_java.jpg

Fred.
« Last Edit: September 19, 2014, 11:01:35 pm by Fred vS »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Java application := fpc application !
« Reply #1 on: September 16, 2014, 04:14:00 pm »

Fred vS

  • Hero Member
  • *****
  • Posts: 1675
    • miXimum is the DJ's best friend
Re: Java application := fpc application !
« Reply #2 on: September 16, 2014, 08:22:57 pm »
Quote
Yes, it's called JNI

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.
>> https://sites.google.com/site/fiensprototyping/fpguitest_java.tar.gz
« Last Edit: September 19, 2014, 10:52:52 pm by Fred vS »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: Java application := fpc application !
« Reply #3 on: September 19, 2014, 02:21:16 pm »
Excellent stuff!!  :) Keep up the good work.

I'll be trying it out this weekend.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Java application := fpc application !
« Reply #4 on: September 20, 2014, 01:59:01 pm »
Are you sure?

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.

Fred vS

  • Hero Member
  • *****
  • Posts: 1675
    • miXimum is the DJ's best friend
Re: Java application := fpc application !
« Reply #5 on: September 20, 2014, 02:31:09 pm »
Quote
Anyway, what is the use for this? If you don't need anything from Java anyway I don't see the point.

Dear Felipe, could you take a look here (and see who made it)  :-X =>
http://wiki.freepascal.org/Using_Pascal_Libraries_with_Java

With some OS (like Android), you may only run Java applications.

The tip of this topic gives the opportunity to all fpc-console developers to transform their (complicated) applications into  working Java applications.  Without the need to deal with Jni.pas. And with only 3 lines of code changed.

By the way, i highly appreciate all the work you have done for Jni and, like you, i think that the couple Java-fpc will have great days.

Thanks.

Fred

« Last Edit: September 20, 2014, 02:47:17 pm by Fred vS »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs