Jump to content
Excelsior Forums


  • Content count

  • Joined

  • Last visited


Community Reputation

0 Neutral

About Chaitawat

  • Rank
  • Birthday 01/01/1
  1. Chaitawat

    How to call DLL by using Java ?

    Hi I really need the solution to fix my problem, problem is i need to call method in DLL by using Java, Before i post this topic i was read a document (Chapter 10 Dynamic linking) and try to execute the example (samples\DLL) then I not clear, because document have a little describe and the example is EXE call DLL. This is my step. 1. I edit dll.prj file to add JETVMPROP %%%%%%%%%%%%%%%%%%%%%%%%%%% %% dll.prj %%%%%%%%%%%%%%%%%%%%%%%%%%% %multi-component applications (EXE + DLLs) can be compiled from command line only. %Please, consult readme.txt from this directory. -jetvmprop=-dll:samplePackage.dllClass:"C:\Program Files\Java\jre1.6.0_02\bin\MyDLL.dll" % -jetvmprop=-dll:samplePackage.*:"C:\Program Files\Java\jre1.6.0_02\bin\MyDLL.dll" % -jetvmprop=-dll:samplePackage.dllClass:MyDLL.dll % -jetvmprop=-dll:samplePackage.*:MyDLL.dll +nolaunchpad -gendll+ -outputname=MyDLL !module samplePackage/dllClass.class 2. Run build.bat for Generate MyDLL.dll 3. Copy MyDll.dll to "C:\Program Files\Java\jre1.6.0_02\bin\" 4. Create new project in Eclipse and create new package name "samplePackage" 5. Create new class "forNameTest.java" and add to "samplePackage" 6. Copy source code from sampleDLL\forName\fotNameTest.java to forNameTest.java in step 5. package samplePackage; public class forNameTest { static public void main(String args[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException { System.out.println("Let's find class compiled in a separate DLL and " + "create its instance"); Class.forName("samplePackage.dllClass").newInstance(); } } 7. Run forNameTest.java and this is result: Let's find class compiled in a separate DLL and create its instance Exception in thread "main" java.lang.ClassNotFoundException: samplePackage.dllClass at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at samplePackage.forNameTest.main(forNameTest.java: Where directory I paste the dll file or Have i something wrong?. Thank you for your help. Chaitawat