This topic is now archived and is closed to further replies.


Using Java Library (DLL)

Recommended Posts

hi, im trying to use a DLL libarary (extension) in my java app. they problem isnt compiling, its running ... is there any way to let the VM know where the DLL is located? the reason im asking, is its for one of my Uni assignments and i dont have write access to the hard-drive (ie. c:/windows/systems32/) the library is JOGL if anyone wants to know. thanks in advance.. Danushka

Share this post

Link to post
Share on other sites

public class MyClass{



public static void main(String[] args){

// Call native class methods....

Also make sure that the dll is in your classpath

java -classpath "C:\LocationOfDll\;"

If you are invoking the VM from C/C++ code then there is a function provided by jni.h that allow you to set the classpath.

Visit and search for the JNI tutorial.. It contains pretty straight forward examples of invoking/embedding and the extension mecahnism

edit: accidentally posted it.. doh..!

[edited by - Rickmeister on March 23, 2004 5:30:51 AM]

Share this post

Link to post
Share on other sites
yea, none of that stuff worked...

i can get it to compile, but when i run it i get the following:
[java cMain -Djava.library.path=g:/java/jenga/]

Exception in thread "main" java.lang.NoClassDefFoundError: net/java/games/jogl/G
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(

heres the source for the applet im trying to run...

import javax.swing.JApplet;

import java.awt.*;

public class cMain extends JApplet implements GLEventListener {

static {

public void init() {
GLCapabilities glc = new GLCapabilities();

GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(glc);

getContentPane().add(canvas, BorderLayout.CENTER);

public void display(GLDrawable gld) {
// the drawing code


public void displayChanged(GLDrawable gld, boolean arg1, boolean arg2) {

public void init(GLDrawable gld) {
// make sure we don''t do anything wrong with OpenGL

gld.setGL(new DebugGL(gld.getGL()));
// set the clear color, this only needs to be done once at the beginning

// of the program after the GL context has been created

gld.getGL().glClearColor(0.0f, 0.0f, 0.75f, 1.0f);

public void reshape(
GLDrawable arg0,
int arg1,
int arg2,
int arg3,
int arg4) {

Share this post

Link to post
Share on other sites
Make sure you have jogl.jar in your classpath. Or even better, put jar files in lib/ext directory of your JVM and dll in bin.
BTW you don't need to load jogl native libraries, it is already done (probably by GLDrawable).

EDIT : For applets it should be a bit harder, because the security manager won't let you load native libraries without guarantees. Can't help you much, I only use standard apps

[edited by - overnhet on March 24, 2004 4:04:53 AM]

Share this post

Link to post
Share on other sites