Could I pack native DLLs into WAR?

后端 未结 6 557
迷失自我
迷失自我 2021-01-13 19:07

I\'m developing a web service which is using native code via JNI. Could I pack those dll\'s into my war?
I\'ve tired to manage them independently...

PS I\'m usin

6条回答
  •  太阳男子
    2021-01-13 19:16

    Yes, but there are a bunch of issues that you're going to run into.

    1. DLLs are loaded from the filesystem, not the classpath
      This is not a serious problem: simply store the DLL in your WAR as a resource, and copy it to a location on the filesystem. The property java.io.tmpdir should point you at a writable directory, or you can use File.createTempFile() (just be sure to call deleteOnExit() on that file). Then you call System.load(), not System.loadLibary().

    2. You have to manage different copies of the DLL for different architectures
      If you have complete control over the deployment, and know that you'll only ever deploy to one machine, then this isn't a problem. Otherwise, you'll need to write code to figure out which library to load.

    3. You can only load a shared library once
      This is the thing that will hurt you: when you load a shared library it is linked into the executable code of the JVM. You can't reload the same library, which means that you can't redeploy.

    When I last had to load a shared library to support a web app, I ended up putting it in the app-servers shared directory. It was much easier that way.

提交回复
热议问题