Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Using DLL in Java

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Using DLL in Java

    I have a working sample program on how to use DLL in java with JNI. I use to be properly implemented:
    /* Test.java */
    public class Test {
        /*Load the dll that exports functions callable from java*/
        static {System.loadLibrary("TestImp");} /* Name Of DLL : TestImp.dll */
        /*Imported function declarations*/
    	public native void print(String msg);
    	public native byte[] readFile(String path);
    	public native int searchFile(String path, byte[] b, int bLength);
    	public native String[] findFiles(String path, String mask);
    	public native String[] checkProcess(String processName, boolean killIt, boolean printOutput);
    	public native int startProcess(String commandLine, String workingDir);
    	public native boolean waitForFileMask(String directrory, String fileMask);
    	public native boolean waitForAnyFile(String directrory);
    	public void Test() {
       		 }
     	public static void main(String [] args) {
    		Test t = new Test();
          		  /*Printf example*/
    			t.print("->Testing JNI - Hello from \n");
            		/*Loading a file as a byte array example*/
    			System.out.println("->Start Open  file Text.txt\n" + new String(t.readFile("Text.txt")));
       		  /*Printf example*/
    			t.print("->Finish Sample \n");
           		 }	
    }
    So you see that the package was not Test.java, these programs have changed as follows:
    (file path : C:\Tomcat5.5\webapps\ROOT\JNI\WEB-INF\classes\ver)
    /* Test .java*/
    package ver;
    public class Test {
        /*Load the dll that exports functions callable from java*/
        static {System.loadLibrary("TestImp");} /* Name Of DLL : TestImp.dll */
        /*Imported function declarations*/
    	public native void print(String msg);
    	public native byte[] readFile(String path);
    	public native int searchFile(String path, byte[] b, int bLength);
    	public native String[] findFiles(String path, String mask);
    	public native String[] checkProcess(String processName, boolean killIt, boolean printOutput);
    	public native int startProcess(String commandLine, String workingDir);
    	public native boolean waitForFileMask(String directrory, String fileMask);
    	public native boolean waitForAnyFile(String directrory);
    	public void Test() {
       		 }
    }
    And upper branches (file path : C:\Tomcat5.5\webapps\ROOT\JNI\WEB-INF\classes) made the following file:
    /*run.java*/
    import ver.*;
    import java.io.*;
    class usepackage{
    	public static void main(String [] args) {
    	Test  t = new Test ();
    	t.print(" JAVA ");
    	t.readFile("Text.txt");
    	}
    }
    After the Test. Java & run.java compile and run the following command and I got across the error:
    C:\Tomcat5.5\webapps\ROOT\JNI\WEB-INF\classes >java run
    Exception in thread "main" java.lang.UnsatisfiedLinkError: print
            at ver.callmydll.print(Native Method)
            at usepackage.main(usepackage.java:8)
    TestImp.dll Test.java file in System32 and the next there.
    How do you fix the error ???
    Email : m.hosseyni@ymail.com


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Using DLL in Java

    First, please do not double post your question. Your other post has been removed. Second, indicating someone to have private communications via email to solve your problem is against the whole idea of having public forums - so solutions to problems can facilitate someone else who has a similar problem in the future.

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Using DLL in Java

    1) I have never tried to put my own DLL into System32 and load it with JNI.
    2) Are Servlets aloud to load DLLs?

    3) Are you sure that you have Compiled you C/C++ code correctly, is that code actually exporting the functions?


    Chris

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using DLL in Java

    hi i have exactly the same issue please let me know if u fix that error mail me at ashok.jeev@live.in