我可以将原生DLL打包到WAR中吗? [英] Could I pack native DLLs into WAR?

查看:411
本文介绍了我可以将原生DLL打包到WAR中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个通过JNI使用本机代码的Web服务。
我可以打包这些dll进入我的战争吗?

我已经厌倦了独立管理它们......

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我是使用maven。

PPS我正在使用Tomcat 7.x

PS I'm using maven.
PPS I'm using Tomcat 7.x

推荐答案

是的,但有一个你将遇到的一堆问题。

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


  1. DLL是从文件系统加载的,而不是类路径

    这不是一个严重的问题:只需将DLL作为资源存储在WAR中,然后将其复制到文件系统上的某个位置。属性 java.io.tmpdir 应指向可写目录,或者您可以使用 File.createTempFile() (只需确保在该文件上调用 deleteOnExit())。然后你调用 System.load() System.loadLibary()

  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().

您必须为不同的架构管理DLL的不同副本

如果您完全控制部署,并知道你只会部署到一台机器,那么这不是问题。否则,您需要编写代码来确定要加载的库。

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.

您只能加载一个共享库

这会对你造成伤害:加载共享库时,它会链接到JVM的可执行代码中。您无法重新加载相同的库,这意味着您无法重新部署。

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.

当我最后不得不加载共享库以支持Web应用程序,我最终把它放在app-servers共享目录中。这种方式要容易得多。

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.

这篇关于我可以将原生DLL打包到WAR中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆