Jump to content
Excelsior Forums
Sign in to follow this  

How to call DLL by using Java ?

Recommended Posts


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




!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");




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:B)

    Where directory I paste the dll file or Have i something wrong?.


    Thank you for your help.


Share this post

Link to post
Share on other sites

You modified the sample in a wrong way. Our support engineer will contact you to make things clear.

Copy MyDll.dll to "C:\Program Files\Java\jre1.6.0_02\bin\"

Please do not copy any DLLs to the Sun JRE (sub)folders. It's not needed to run the sample and may break other Java applications.

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