Jump to content
Excelsior Forums

chandra_excel

Members
  • Content count

    0
  • Joined

  • Last visited

    Never

Community Reputation

0 Neutral

About chandra_excel

  • Rank
    Newbie
  • Birthday 01/01/01
  1. getMethod fine in Java but not yet in JET

    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
  2. getMethod fine in Java but not yet in JET

    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.
  3. 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.
  4. getMethod problem in dynamic loading of dll

    With the changes you suggested, the code works neat and I get the method invoked just fine.? (I have removed the line "Objects[] arguments..." and used "m.invoke(instance)" for testing.? Thank you. Passing some parameter types instead of null/nothing in the case of Class[] parameterTypes and using arguments like "this" or "someClassName.class" instead of null/nothing while passing arguments, are my next tasks.? Will explore on that and come back later.? Compilation of such code works fine now in normal Java compiling but not after JET exe is built.? Will post about it under a separate topic more clearly. Many thanks again, Chandra.
  5. getMethod problem in dynamic loading of dll

    Thank you very much.? Removing 'null' works perfect.? Original purpose was indeed trying to load the dll dynamically and invoke some method in it (here, it is 'callMe').? I added the following lines after getting the method: Object[] arguments = new Object[] {this}; try { m.invoke(c, arguments); } catch (Exception e3) // few exceptions seems to occur, so using general 'Exception' { System.out.println("Method found. But invoking throws: " + e3.toString()); } As expected, using "this" causes a non-static variable being referenced and compiling itself does not finish.? I see this is not JET problem, however a hint might help.? Will explore more on Java groups mean-while. Thanks, Chandra.
  6. Hi, I have modified the example codes of ..JET\samples\dll\dynamic.? I get 'no such method' exception when using the new code, compile them using JSE1.5.0 and build them using JET 90-day trial version.? DLL loads fine but method cannot be accessed. Any help please?? Or is this limitation of trial version? Codes: Code for exe: ------------------- public class DynamicLoad { static public void main (String args[]) throws InstantiationException, IllegalAccessException { System.out.println ("DLL is not loaded yet."); System.out.println ("Let's find class (and load DLL)"); try { Class c = Class.forName ("ClassFromDLL"); System.out.println ("Class found (DLL is loaded successfully)"); c.newInstance(); // added to example try { Class[] parameterTypes = new Class[] {null}; java.lang.reflect.Method m = c.getMethod("callMe", parameterTypes); // problem is here } catch (NoSuchMethodException e2) { System.out.println("Method not found. " + e2.toString()); } } catch (ClassNotFoundException e) { System.out.println ("Class not found. Maybe DLL is absent?"); } } } Code for dll: --------------- public class ClassFromDLL { public ClassFromDLL() { System.out.println ("_______Hi from DLL!_______"); } // new method public void callMe() { System.out.println ("_______Hi from DLL's callMe!_______"); } } Many thanks Chandra
×