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
- URL url = Foo. Class. getresource ("foo. Class ");
- String Path = (new file (URL. getpath (). getparent ();
- 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