Jump to content
Excelsior Forums
Sign in to follow this  
chandra_excel

getMethod fine in Java but not yet in JET

Recommended Posts

Hi,

I have a "getMethod" code, which works fine in J2SE 1.5.0_04 but throws no-such-method exception in JET 4.0 trial version.

Kindly see codes in the following codes. The purpose is this: the EXE file and the API.java (with fake functions) will be distributed to user.? Then, any dll created by the user using API.java (fake) should work with the EXE fine.?

I try the following sequence:

(EXE and dll are compiled/built in separate folders; copied to appropriate folders when used).

1. Compile the MainProgram.java using javac.

2. Build the exe using JET.?

3. Compile the Plugin.java using javac.

4. Build the dll using JET.

5. Running the EXE will load the "Plugin.dll" fine, but cannot find the method invoked there.?

6. Running the MainProgram.class using "java" will load the "Plugin.class" fine and also invoke the method.

Any requirement of JET is missed here?? Help please.? Also tell me if codes should be explained in detail.. code contents:

==========================

MainProgram.java

==========================

public class MainProgram

{

public static void main (String argv[])

{

API api = new API();

}

}

==========================

API.java

==========================

public class API

{

public API()

{

try

{

Class c = Class.forName("Plugin");

Object instance = c.newInstance();

// line below causes 'no such method exception' in JET 4.0,

// but ok in J2SE 1.5.0_04

java.lang.reflect.Method m = c.getMethod("setData", API.class);

// above problem should be solved first, to get here

Object[] arguments = new Object[] {this};

m.invoke(instance, arguments);

}

catch(Exception e)

{

System.out.println("forName throws: " + e.toString());

}

}

// this method is called from user Plugin

public void printSomething(String str)

{

System.out.println("" + str);

}

}

==========================

API.java (fake)

==========================

public class API // this is fake API given to user

{

public API() {

}

public void printSomething(String str) { // fake function

}

}

==========================

Plugin.java

==========================

public class Plugin

{

API api;

public Plugin() {

}

public void setData(API apiIn)

{

api = apiIn;

api.printSomething("\nHi from plugin.\n");

}

}

==========================

And JET prj file used for exe is this:

==========================

% exe

+nolaunchpad

-lookup = *.sym = .\sym;

-lookup = *.bod = .\bod;

-lookup = *.obj = .\obj;

-classabsence=handle

+ignorememberabsence

-jetvmprop=-dll:Plugin:Plugin.dll

!module MainProgram.class

==========================

JET prj file used for dll is this:

==========================

% dll

+nolaunchpad

-lookup = *.sym = .\sym;

-lookup = *.bod = .\bod;

-lookup = *.obj = .\obj;

-classabsence=handle

+ignorememberabsence

-gendll+

!module Plugin.class

Sorry for the too long report, but thought it helps to demonstrate the problem.

Many thanks

Chandra.

Share this post


Link to post
Share on other sites

On our side, this sample works fine with JET 4.0 as well as with Sun JRE 5.0.

Please, show here the exact procedure how you run it.

Share this post


Link to post
Share on other sites

Relieved to hear that it works fine on your side for both JET and Sun JRE.? So, the code is ok and JET prj file contents are also ok.? Procedure I follow is this:

1. I installed Java 1.5.0_04 from Sun and it is located at C:\Program Files\Java\jdk1.5.0_04 in my PC (WinXP).? So, for compiling my java files, I use "C:\Program Files\Java\jdk1.5.0_04\bin\javac fileName.java" in a batch file.

2. I installed JET 4.0 and it comes with 1.5.0_04 pre-compiled, right?? So, I did not do anything on that and use it as such.? I use the "prj" files with contents shown before to compile the dll and exe files.

3. I use two separate folders for compiling the exe and the dll.? I create the exe first and then the dll (the sequence should not influence anyway in this dynamic loading case, right).

4. I copy the dll to exe folder and try running the EXE.

Some more info on that:

===================================

contents of batch file to compile MainProgram.java:

===================================

C:\Progra~1\Java\jdk1.5.0_04\bin\javac MainProgram.java

The above creates MainProgram.class and API.class in its folder.

===================================

contents of batch file to compile Plugin.java:

===================================

C:\Progra~1\Java\jdk1.5.0_04\bin\javac Plugin.java

The above creates Plugin.class and API.class in its folder.

Then I use "jc =p MainProgram.prj" in a batch file to create the exe in its folder and use "jc =p Plugin.prj" in another batch file to create the dll in its folder.

And, you mentioned Sun JRE 5.0.? Should I install an exact Java SDK 1.5.0 version and compile it using JET?

Thanks,

Chandra.

Share this post


Link to post
Share on other sites

Finally..... I found the mistake I have been making in compiling the Plugin.dll.? When I compile this dll, I must remove the API.class created using fake API.java.? So, it works fine now.

Many thanks for the reply, I was able to focus on the methodology.

Regards

Chandra

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×