Dynamic loading of DLLs and Jar file

Hi,
i'm trying to load the DLLs and the jar file from my code but i'm not able.

Here is the code i use:

        //Allow loader
        NativeLibLoader.disableLoading();
 
        //Seems to have to load awt first
        java.awt.Toolkit.getDefaultToolkit();
        System.loadLibrary("jawt");
       
        //Load the jogl jar file
        URL urlJOGL = (new File(ThinClient.getPath() + "jogl.jar")).toURL();
        URL[] urls = { urlJOGL };          
        URLClassLoader classLoader = new URLClassLoader(urls);
 
        //Load the DLLs
        System.load(ThinClient.getPath() + "jogl.dll");
        System.load(ThinClient.getPath() + "jogl_awt.dll");



After this, i'm getting this error

java.lang.NoClassDefFoundError: com/sun/opengl/impl/NativeLibLoader
...



It was like if my jar wasn't loaded. Anybody have an idea?

I want to do this cause on Windows i'm able to put the jar into the lib/ext folder and the DLLs into the bin folder of the JRE the first time, but i need a cross platform solution. On Linux i can't do this, cause the JRE folders are 99% with root acces, so i cannont use this method with normal user. This solution seems good cause i put the files into the home directory of the user (i'll adapt the code for others os after i'll be able to load the stufss dynamically).

thx a lot!!!

P.S.: I already post the code to JOGL forum, but it's not a specific JOGL problem it's why i posted it here.
bumpertAsked:
Who is Participating?
 
Mayank SAssociate Director - Product EngineeringCommented:
>> don't know if something like this could be done into Windows computer.

If it can be done in Java, it can be done on Windows I guess. But can you not get it done just after Java is installed on the machine (the installation will be done by an admin I suppose).
0
 
Mayank SAssociate Director - Product EngineeringCommented:
The JAR file has to be present in the class-path:

http://www.mindprod.com/jgloss/classpath.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Also, the DLLs need to be present in any directory which is present in java.library.path. You can find out the list of those directories using:

System.out.println ( System.getProperty ( "java.library.path" ) ) ;

You can perhaps also change it to refer to any directory you want:

System.setProperty ( "java.library.path", System.getProperty ( "java.library.path" ) + ";" + yourDirectoryPath ) ;
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
bumpertAuthor Commented:
I know, but it have another way to do this like i'm trying to do by loading it dynamically.

I cannot set the classpath on all users' computer (i'm with an applet, and i can load the files from the computer cause i signed it) and i'll try to find the post i had, but i read somewhere that the JRE don't take care about the classpath you set with the System.setProperty function, so it's not a good solution for me.

Thx for your help
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Keep the JAR/ DLL in directories where you have permission to place them (based on the platform) and add them to the class-path/ library-path
0
 
bumpertAuthor Commented:
i made my first post before seeing your second one.
I'll give another try to the solution you gave me (already tried it without succes, but maybe i was doing something wrong). I'll give you feedback as soon as i can

thx for help
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> JRE don't take care about the classpath you set with the System.setProperty function

I didn't ask you to change the class-path using that. It was for the library-path. Anyway that's not required - you can just find out what it is by printing that value and place the DLL in one of those directories.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> I cannot set the classpath on all users' computer (i'm with an applet

Oops, didn't know you were using an applet that's downloaded to the user's computer. Well in that case, I guess somehow you'll have to make sure the JAR and DLL are available on each user's computer for loading (when do the JAR/ DLL files get copied there? At that time, perhaps the class-path will also need to be set).
0
 
bumpertAuthor Commented:
>> Keep the JAR/ DLL in directories where you have permission to place them (based on the platform) and add them to the class-path/
>> library-path

Ok for this

>> I didn't ask you to change the class-path using that. It was for the library-path. Anyway that's not required - you can just find out what it
>> is by printing that value and place the DLL in one of those directories.

After doing
System.setProperty ( "java.library.path", System.getProperty ( "java.library.path" ) + ";" + ThinClient.getPath() ) ;
and
System.setProperty ( "java.class.path", System.getProperty ( "java.class.path" ) + ";" + ThinClient.getPath() ) ;
to set both libray path and classpath, if i print before and after these command, i got the library and class path modified with the good directory that is the one i need, but after doing this, when my applet load i got:

java.lang.NoClassDefFoundError: com/sun/opengl/util/BufferUtil

like if my jar wasn't existing

and if i put my jar into the lib ext of the JRE to check if, at least,  the library work, i got the same problem, like if my library didn't exist

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path

>> Oops, didn't know you were using an applet that's downloaded to the user's computer. Well in that case, I guess somehow you'll have
>> to make sure the JAR and DLL are available on each user's computer for loading (when do the JAR/ DLL files get copied there? At that
>> time, perhaps the class-path will also need to be set).

Already done, on each loading of the applet, i check if the files are there, if not i write it on the user computer (my applet is signed so i have the right to do this).

Any ideas what happen?
thx for help
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> got the library and class path modified with the good directory that is the one i need but after doing this, when my
>> applet load i got: java.lang.NoClassDefFoundError: com/sun/opengl/util/BufferUtil like if my jar wasn't existing

In class-path, you need to add the entire JAR (full-path of the file = directory + file-name), not the containing directory.

>> and if i put my jar into the lib ext of the JRE to check if, at least,  the library work, i got the same problem, like if my
>> library didn't exist Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path

Putting the JAR in lib\ext won't help the DLL. You need to put the DLL in some directory too, that is in java.library.path. For example, Windows\system32
0
 
bumpertAuthor Commented:
>> In class-path, you need to add the entire JAR (full-path of the file = directory + file-name), not the containing directory.

Not necessary, but i tried and still don't work

>> Putting the JAR in lib\ext won't help the DLL. You need to put the DLL in some directory too, that is in java.library.path. For example,
>> Windows\system32

I know, it was to see if at least the setProperty of the libreary path worked.

So by now, nothing works :(

I'll try to find the place i read that when set by the System.setProperty the JRE don't really care, you need to set it in the Java Parameters or in the command line when you start a standalone application (it was a bug but in an old jre version, maybe now it's fixed).

Any others ideas?

thx a lot for your help
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Not necessary, but i tried and still don't work

Its is necessary :) the entire JAR has to be in the class-path (unless it is in jre\lib\ext - because the JVM always recognizes all JARs in that folder, otherwise the JAR itself has to be in the class-path).

>> Any others ideas?

Well you can, of course, specify a class-path while running the application, as a command-line switch, if that helps:

http://www.mindprod.com/jgloss/javaexe.html
0
 
VenabiliCommented:
JUst a warning: If you want to make it platform-indepndnd make sure you use the correct classpath separator.
It is ";" under Windows and ":" under Unix. Use the System.getProperty( "path.separator" )  instead of direct value when building the path in JAva

I know this does not solve the problem, just mentioning it.

Venabili
0
 
VenabiliCommented:
>>I'll try to find the place i read that when set by the System.setProperty the JRE don't really care
By the way, I believe you had seen this:
http://gcc.gnu.org/ml/java/2003-07/msg00183.html
And here:
http://www.artima.com/legacy/design/rtci/messages/61.html
The java System property java.class.path is used to build a linked link when the JRE is instantiated, then is not re-read. Therefore, changes you make to the property don't really do anything to the existing virtual machine.
0
 
VenabiliCommented:
A workaround may be to create a class which reads the needed data and instead of setting the classpath, simply create a new java process, giving the new classpath to it and thus startig your application. Worth a try probably if all this is the first step?

Sorry for the multyposting... Just remember something after I press Submit...
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Therefore, changes you make to the property don't really do anything to the existing virtual machine.

Yeah, thought so.
0
 
bumpertAuthor Commented:
>> Its is necessary :) the entire JAR has to be in the class-path (unless it is in jre\lib\ext - because the JVM always recognizes all JARs in that
>> folder, otherwise the JAR itself has to be in the class-path).

Oh i was thinking that you said that i need to set the fullpath include the jar file into the classpath (but i tried to two way). My Jar file is physicaly into the folder i had into the classpath.

>> Well you can, of course, specify a class-path while running the application, as a command-line switch, if that helps:

I can't, one of the obligation i have is to run it into an applet.
So the only other solution

>>JUst a warning: If you want to make it platform-indepndnd make sure you use the correct classpath separator.
>>It is ";" under Windows and ":" under Unix. Use the System.getProperty( "path.separator" )  instead of direct value when building the
>> path in JAva

Already think of this one, if it was me i'll make the applet ava

>> By the way, I believe you had seen this:
Yes i read a thread with this explication

>> A workaround may be to create a class which reads the needed data and instead of setting the classpath, simply create a new java
>> process, giving the new classpath to it and thus startig your application. Worth a try probably if all this is the first step?
I don't think i can't do this into the browser, cause when an applet is started and the jre is started by an applet into the browser, there is no java process but it's a plugin, so it's integrated into the browser process. It's why you have to kill all the browser instance to be able to have a new java process. In my case i can't cause the user have maby open others pages...

>> Sorry for the multyposting... Just remember something after I press Submit...
No problem, it's funny, cause i received a mail, starting to answer and as soon as i'm goind to press submit, i receive another notificaion mail. Update the page, answer the seconde, and so on... lol
0
 
VenabiliCommented:
Oops. I forgot that we have an applet here. Sorry :)

Hmmmm.. no ideas right now but I will surely check a few things.

As for the file-separator - I just mentioned it because I saw ";" above :)
0
 
bumpertAuthor Commented:
Oups i didn't finish my so the only other solution i'm thinking of, is to put all my files (DLLs and JAR) into the folder i created into the user home folder, like i do now. Adding the parameter to the Java Control Panel, so by default each applet will use these parameter before loading the applet. So the first time user will need to restart the browser but after the params is there all will be ok.

The only problem i see with this, it's that the only way i know how to do this with my application is to open the deployment.properties but it's a mess. This file didn't exist since the user have already open, at least one time, the Java Control Panel. After you need to find the good line for the good JRE to add the params, ... it's a mess

Maybe it could be a way to do what i need, but need to find a better solution to add parameters into the Java Control Panel by myself in a good way...

New ideas?
thx for help
0
 
bumpertAuthor Commented:
>> Oops. I forgot that we have an applet here. Sorry :)
No problem :)

>> Hmmmm.. no ideas right now but I will surely check a few things.
Thx a lot for your time and help

>> As for the file-separator - I just mentioned it because I saw ";" above :)
No problem, i made some test into Windows and as soon as i got a working solution under Windows, all made the code to work into Windows and Linux os

thx a lot for your help
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> is to put all my files (DLLs and JAR) into the folder i created into the user home folder

Well, if the DLL is in the PATH and the JAR in the class-path (not the directory but the entire JAR's full-path) then I think you should be fine. Right now, you said it did not work after you put the entire JAR into the class-path. How did you put it into the class-path? Did you test on Windows with My Computer -> Properties -> Advanced -> Env Vars? If so, you will need to restart the browser or command-window (wherever you test), I guess.
0
 
bumpertAuthor Commented:
For summary the problem
------------------------------

It work if:

- I put the jar into the lib/ext of the JRE and the DLLs into the bin of the JRE, but it's not a multi-platform solution cause when the JRE directorys into Linux are to root, i cannot add it by myself with the applet when another user run it.
- I put the jar and DLLs into a custom folder and add it manually to the classpath with the environement variable into Windows, but for now, it's not a good solution cause i can't seems to set dynamically the classpath i need.
- I put the jar and DLLs into a custom folder and add the right option into the Java Control Panel -> Java Runtime Settings -> Java Runtime Parameters manually into the right JRE box.

So, i need to find a solution by:

- be able to load the DLL and JAR dynamically like i was trying to do (but I doesn't seems to be able).
- Find a way to add my files into the class path with my applet.
- Find a way to add the parameters i need into the Java Control Panel.

Personally, i prefer the first option but it don't seems to be a working solution so my second choice would be to add the good parameters into the Java Control Panel (i know which params to it here). So is there a safe way to add this parameters? Or do you have any others ideas i can try? or solution to my problems?

thx a lot for help
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> I put the jar into the lib/ext of the JRE and the DLLs into the bin of the JRE

That might not work on some Windows versions too if you have it installed in Program Files and you are a non-admin user (I mean, adding the JAR and DLL).
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I think you need to do the job of adding the JAR to the class-path or the jre\lib\ext, and the DLL to the Path manually through an admin/ root on all platforms before downloading the applet (its a one-time activity).
0
 
bumpertAuthor Commented:
>> That might not work on some Windows versions too if you have it installed in Program Files and you are a non-admin user (I mean,
>> adding the JAR and DLL).

Oh yeah, didn't think of this one so it's not only a Linux bad solution...

>> I think you need to do the job of adding the JAR to the class-path or the jre\lib\ext, and the DLL to the Path manually through an admin/ >> root on all platforms before downloading the applet (its a one-time activity).

I had an idea for this, with some application GUI that need to do thing in root, you do your stuff and when root is need a popup come to ask the root password to do the root stuff. It could be an idea, but didn't know how to do this and don't know if something like this could be done into Windows computer.

thx for help
0
 
bumpertAuthor Commented:
>> If it can be done in Java, it can be done on Windows I guess.

For sure, but i don't know how to do this in Java :)

>> But can you not get it done just after Java is installed on the machine (the installation will be done by an admin I suppose).

Yes but i don't think is a good solution for my problem. Cause we have many clients on big company that have restricted acces to the computer so Java is already installed and after it's a big procedure or time request to have the technician come to add this or that program.

So i think, the best solution i need to try to do is by adding params to the Java Control Panel... but don't know how to do this by now. I'll try to search. If you have any idea please let me know.

thx for help.
0
 
bumpertAuthor Commented:
I didn't have much time to put on this, but i'll try to check this as soon i as i have time and give you some feedback...
0
 
bumpertAuthor Commented:
I have another good discussion about my problem on this forum: http://forum.java.sun.com/thread.jspa?messageID=4219293

Maybe that could help people help me :)

thx a lot
0
 
bumpertAuthor Commented:
Don't close it, i just didn't have time to continu this but i'll have. The answer didn't give me a perfect solution but many way to work on it. I will probably give the points the people that help me as soon as my problem will really be fix :)
0
 
bumpertAuthor Commented:
I succeded in change the mind of my boss and do it with Java WebStart. So i'll try to make what i want with Java WebStart and give you feedback as soon as possible. I think i'll be more easy...

Thx for help
0
 
bumpertAuthor Commented:
I have been able to do it easily with Java Webstart (it could be so easy if my boss wanted this before)

thx a lot to all
i give point to people that help me a lot!!!
0
 
bumpertAuthor Commented:
Sorry i wasn't able to give point to may people at the time so i give it to the one that help me more (not that others didn't help me...) sorry

and thx a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.