8

There's Java jar binary library with described classes/functions making some usefull things (nothing special just plain Java - no JNI). No sources available.

There's a task to call those functions directly from Delphi. How to do that?

P.S. I know nothing about Delphi, but I know a lot about Java.

2
  • 2
    It's appropriate that you'd mention JNI since that's exactly what you'll use. Remember that JNI is a two-way street. It not only allows Java code to call native code, but also allows native code to call Java code. Commented Nov 2, 2011 at 6:34
  • 2
    I didn't know if this was even possible, but apparently it is using JNI. Google is Omniscient: home.pacifier.com/~mmead/jni/delphi/informant/di200310kw.htm Commented Nov 2, 2011 at 6:36

4 Answers 4

6

No you can't the way to go is JNI.

A few resources:

Unless you have too much time on your hands, in which you could decompress the JAR files (they are ZIP files), write your own Java VM in Delphi and go from there ;-)

Sign up to request clarification or add additional context in comments.

3 Comments

I would favour SO search instead of Google: stackoverflow.com/search?q=%5Bdelphi%5D+jni
In fact I do have sources of those jar, since I'm author. Purpose was to give another party not sources, but just binary jar with described input/output. So I will immediately develop JNI gate to my jar. Thanx a lot!
@splash thanks for the time. In my experience, it varies; sometimes the google search is much better, sometimes the SO search. It is good to try both.
1

Does the jar file contains a main class that can be called from the command line? If so problem solved Delphi can execute command line operations. If there is no main class you can create one that calls the original jar file.

Comments

1

As a fast and simpler alternative to the low level, time consuming and error prone JNI from Delphi option, you should try Java for Delphi.

You'll be working with an object oriented API, would need a fraction of the code when compared to JNI and solve your Delphi/Java integration problem in a few hours instead of days, weeks (or months depending on the use case).

As an example, below is the public declaration of the Delphi type corresponding to java.lang.String with a code extract showing how it can be used.

Don't hesitate to contact J4SOFT, will be glad to help you.

Procedure Sample;
var
  AJavaString: Ijava_lang_String;
  AValue: string;
begin
  AJavaString := Tjava_lang_String.Create('A value'); 
  AValue :=  AjavaString.ToString;
  if AJavaString.StartsWith('A') then
  ...
end;

...
type
  Tjava_lang_String = class(Tjava_lang_Object, Ijava_lang_String)
  public
    constructor Create;
    constructor Create(p0: string);
    constructor Create(p0: Ijava_lang_StringBuffer);
    constructor Create(p0: Ijava_lang_StringBuilder);
    constructor Create(p0: TjxByte1DArray);
    constructor Create(p0: TjxByte1DArray; p1: Longint);
    constructor Create(p0: TjxByte1DArray; p1: Longint; p2: Longint);
    constructor Create(p0: TjxByte1DArray; p1: Longint; p2: Longint; p3: Longint);
    constructor Create(p0: TjxByte1DArray; p1: Longint; p2: Longint; p3: string);
    constructor Create(p0: TjxByte1DArray; p1: string);
    constructor Create(p0: TjxChar1DArray);
    constructor Create(p0: TjxChar1DArray; p1: Longint; p2: Longint);
    constructor Create(p0: TjxInt1DArray; p1: Longint; p2: Longint);
    function CharAt(p0: Longint): Char;
    function CodePointAt(p0: Longint): Longint;
    function CodePointBefore(p0: Longint): Longint;
    function CodePointCount(p0: Longint; p1: Longint): Longint;
    function CompareTo(p0: string): Longint;
    function CompareToIgnoreCase(p0: string): Longint;
    function Concat(p0: string): string;
    function ContentEquals(p0: Ijava_lang_StringBuffer): Boolean;
    class function CopyValueOf(p0: TjxChar1DArray): string;
    class function CopyValueOf(p0: TjxChar1DArray; p1: Longint; p2: Longint): string;
    function EndsWith(p0: string): Boolean;
    function Equals(p0: Ijava_lang_Object): Boolean; reintroduce;
    function EqualsIgnoreCase(p0: string): Boolean;
    class function Format(p0: string; p1: Tjava_lang_Object1DArray): string;
    function GetBytes: TjxByte1DArray;
    procedure GetBytes(p0: Longint; p1: Longint; p2: TjxByte1DArray; p3: Longint);
    function GetBytes(p0: string): TjxByte1DArray;
    procedure GetChars(p0: Longint; p1: Longint; p2: TjxChar1DArray; p3: Longint);
    function HashCode: Longint;
    function IndexOf(p0: Longint): Longint;
    function IndexOf(p0: Longint; p1: Longint): Longint;
    function IndexOf(p0: string): Longint;
    function IndexOf(p0: string; p1: Longint): Longint;
    function Intern: string;
    function IsEmpty: Boolean;
    function LastIndexOf(p0: Longint): Longint;
    function LastIndexOf(p0: Longint; p1: Longint): Longint;
    function LastIndexOf(p0: string): Longint;
    function LastIndexOf(p0: string; p1: Longint): Longint;
    function Length_: Longint;
    function Matches(p0: string): Boolean;
    function OffsetByCodePoints(p0: Longint; p1: Longint): Longint;
    function RegionMatches(p0: Longint; p1: string; p2: Longint; p3: Longint): Boolean;
    function RegionMatches(p0: Boolean; p1: Longint; p2: string; p3: Longint; p4: Longint): Boolean;
    function Replace(p0: Char; p1: Char): string;
    function ReplaceAll(p0: string; p1: string): string;
    function ReplaceFirst(p0: string; p1: string): string;
    function Split(p0: string): TjxString1DArray;
    function Split(p0: string; p1: Longint): TjxString1DArray;
    function StartsWith(p0: string): Boolean;
    function StartsWith(p0: string; p1: Longint): Boolean;
    function Substring(p0: Longint): string;
    function Substring(p0: Longint; p1: Longint): string;
    function ToCharArray: TjxChar1DArray;
    function ToLowerCase: string;
    function ToString: string;
    function ToUpperCase: string;
    function Trim: string;
    class function ValueOf(p0: Char): string;
    class function ValueOf(p0: Double): string;
    class function ValueOf(p0: Single): string;
    class function ValueOf(p0: Longint): string;
    class function ValueOf(p0: Int64): string;
    class function ValueOf(p0: Ijava_lang_Object): string;
    class function ValueOf(p0: Boolean): string;
    class function ValueOf(p0: TjxChar1DArray): string;
    class function ValueOf(p0: TjxChar1DArray; p1: Longint; p2: Longint): string;
    property CASE_INSENSITIVE_ORDER;
  end;

Comments

0

If you decompile binary file and produce some kind of a primitive java source, then you might consider using Java to Pascal converter. This should be doable without much trouble since you said that JAR is nothing special or complex.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.