java 将 dll 转换为 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16886588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting dll to jar
提问by Dennis Nerush
I'm trying to find a way to convert a dll to a jar file. I have a .net application that communicates with a java application. The core entities are .net objects which I have to duplicate manually in java. I've read about IKVM but it seems that it converts only jars to dlls and not the other way around.
我正在尝试找到一种将 dll 转换为 jar 文件的方法。我有一个与 java 应用程序通信的 .net 应用程序。核心实体是我必须在 java 中手动复制的 .net 对象。我读过 IKVM,但它似乎只将 jars 转换为 dll,而不是相反。
Edit: If there is a tool that creates java classes from a dll it is also fine. Thanks in advance
编辑:如果有一个工具可以从 dll 创建 java 类,它也很好。提前致谢
采纳答案by chamakits
There isn't such a tool.
没有这样的工具。
A dll is a natively compiled library. That means its been compiled down to machine code. Probably compiled by a C/C++/C# compiler.
dll 是本机编译的库。这意味着它被编译成机器码。可能由 C/C++/C# 编译器编译。
A jar file is a zip file that contains '.class' files, which are files compiled down to 'java virtual machine code'. Probably compiled by a java/clojure/scala compiler.
jar 文件是包含“.class”文件的 zip 文件,这些文件是编译为“java 虚拟机代码”的文件。可能由 java/clojure/scala 编译器编译。
These are two very different incompatible things.
这是两种截然不同的不相容的东西。
It's not impossible to create such a tool that would do this translation, but it would definitely be an extremely difficult task, as it would entail translating from one machine code, to another, and would need to manage multiple issues like dependency solving, different type structure etc.
创建这样一个工具来进行这种翻译并非不可能,但这绝对是一项极其艰巨的任务,因为它需要从一种机器代码翻译成另一种机器代码,并且需要管理多个问题,例如依赖项解决、不同类型结构等
HOWEVER, I'm imagining that you want to do this because you want to use a DLL within some java code. That is somewhat possible, but is actually quite complicated. You'll need to use the JNI.
但是,我想您要这样做是因为您想在某些 Java 代码中使用 DLL。这在某种程度上是可能的,但实际上相当复杂。您将需要使用 JNI。
Take a look at this question as it might help you achieve what you want to do: Calling C++ dll from Java
看看这个问题,因为它可能会帮助您实现您想要做的事情: Calling C++ dll from Java
回答by chamakits
This is actually an easy task to perform. Converting .dll to .jar is as simple as using com4j and a couple of commands on the command line.
这实际上是一项容易执行的任务。将 .dll 转换为 .jar 就像在命令行上使用 com4j 和几个命令一样简单。
- Download com4j.
- Open command line and navigate to com4j directory in above step.
- Execute below command.
- 下载 com4j。
- 在上述步骤中打开命令行并导航到 com4j 目录。
- 执行下面的命令。
java -jar tlbimp.jar -o outputFolder -p nameOfPackage "pathToFile"
java -jar tlbimp.jar -o outputFolder -p nameOfPackage "pathToFile"
Then jar the results with the following:
jar cf desiredJarName.jar folderYouWantJard
然后使用以下内容对结果进行 jar 处理:
jar cf requiredJarName.jar 文件夹YouWantJard