Results 1 to 6 of 6
  1. #1
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default [Applet] Set java.library.path

    I wanna load an "*.dll" file in java, but I've read that I have to set an "java.library.path".

    Now when I set the java.library.path in the applet self it won't use it.
    When I use the appletviewer and set the java.library.path with the command:
    Java Code:
    appletviewer -J-Djava.security.policy=java.policy.applet -J-Djava.library.path=D:/java_libraries/j3d-1_5_2-windows-i586/bin index.html
    The applet uses the java.library.path given in the startup command.

    But I want to let it work in each browser.

    java-code:
    Java Code:
    import java.awt.Color;
    import java.awt.Graphics;
    
    public class loader extends java.applet.Applet
    {
    	private String oldJLP;
    	private String oldUD;
    	
    	private boolean error = false;
    	private String message;
    	
    	public void init()
    	{
    		oldJLP=System.getProperty("java.library.path");
    		oldUD=System.getProperty("user.dir");
    		System.setProperty("java.library.path", "D:\\java_libraries\\j3d-1_5_2-windows-i586\\bin");
    		System.setProperty("user.dir", "D:\\java_libraries\\j3d-1_5_2-windows-i586\\bin");
    		try{
    			System.loadLibrary("j3dcore-d3d");
    			message = "j3dcore-d3d loaded";
    		}catch(UnsatisfiedLinkError ex){
    			error=true;
    			message = ex.getMessage();
    		}
    	}
    	
    	public void paint(Graphics g)
    	{
    		g.drawString("old-JLP: " + oldJLP, 10, 10);
    		g.drawString("new-JLP: " + System.getProperty("java.library.path"), 10, 30);
    		g.drawString("old-UD: " + oldUD, 10, 50);
    		g.drawString("new-UD: " + System.getProperty("user.dir"), 10, 70);
    		if(error){
    			g.setColor(Color.red);
    			g.drawString("message: " + message, 10, 90);
    		}else{
    			g.setColor(Color.green);
    			g.drawString("message: " + message, 10, 90);
    		}
    	}
    }
    html-code:
    Java Code:
    <applet code="loader.class" archive="loader.jar" width="1000" height="500"></applet>
    java.policy.applet
    Java Code:
    /* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
    /* DO NOT EDIT */
    
    grant {
      permission java.security.AllPermission;
    };
    I use the IDE Eclipse for create and test it at the most times.

    The "j3dcore-d3d" is in "D:\java_libraries\j3d-1_5_2-windows-i586\bin".

    Does someone know how I can set the java.library.path while the applet is running, tell me!

    Thanks,
    Dennis

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    The clients that want to use it will have to change their configurations.

  3. #3
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default

    But I can sign the jar, so they have to accept the applet to run.

    And I only want to set this changes temporary, only while the applet is running and only used by applet.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Doesn't matter. The library path needs to be set before the JVM is started in the browser. By the time it gets to the Applet, its too late. The clients will need to change their configuration.

  5. #5
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default

    Okay,
    But then it is quite strange that there is an function
    Java Code:
    System.setPropery("java.library.path", "...");
    :P

    Thank you for your help, I'll look for another way to let it work.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    No, it's not quite strange. However, that particular system property is there for "informational" purposes only. That property list is nothing but a list of Strings from values that were set before the program started. There is no guarantee that any of those will be "looked at" and used dynamically. most of them will have been read and their value saved and won't be looked at again (by the JVM, but maybe by you).

Similar Threads

  1. Replies: 2
    Last Post: 02-03-2011, 03:06 AM
  2. setting class-path & Library Path in ubantu
    By programmer_007 in forum Eclipse
    Replies: 18
    Last Post: 02-22-2010, 12:31 PM
  3. java.library.path problems
    By deepthought in forum New To Java
    Replies: 1
    Last Post: 02-15-2010, 08:06 AM
  4. URGENT: How to include a library in Java class path?
    By gsmurthy30 in forum New To Java
    Replies: 3
    Last Post: 09-15-2008, 04:58 PM
  5. URGENT: How to include a library in Java class path?
    By gsmurthy30 in forum Advanced Java
    Replies: 1
    Last Post: 09-15-2008, 08:39 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •