Path processing for dll file placement during Jni Development

Source: Internet
Author: User

When I first arrived at a new company, I got a tough task. After thinking about a lot of methods, I finally want to use the Java com bridge. Jacob is a mature open-source project that can easily call COM components. All JNI users know that the local library should be placed in the system path so that the Java Process can find and dynamically load the local library during running. We can use the environment variable system. getproperty ("Java. Library. Path") to view the path of the local library searched by the current JVM.

In this case, you may encounter a problem. When deploying an application, remember to copy the local database to the path specified by the Environment Variable path. Generally, on the Windows platform, copy the file directly to the C:/Windows/system32 directory. But what should I do if I want to deploy it on another machine? In addition to the Java program, it is really troublesome to copy the local library to the correct directory. So I want to see how to solve this problem.

First, put the local library and class file together, use class. getresource (STR) to find the path, and then add it to the java. Library. Path Environment:

Code
  1. URL url = Foo. Class. getresource ("foo. Class ");
  2. String Path = (new file (URL. getpath (). getparent ();
  3. System. setProperty ("java. library. path", path );

The only weakness in the United States means that deleting a DLL fails when the system is disabled. Think about it. The DLL is being used by the program and cannot be deleted. After turning over the API, Java does not seem to have provided the unload local library function.
To solve such a small problem, Luo luocheng likes a large article and commits a sin. Later, Jacob was not used in this project. Sorry for the audience.

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1772149

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.