程式語言為什麼有需要互相調用呢?
原因很簡單

  • 情況一

有一個很多不同程式須(使用)執行一個相同一程序,然後那些程序執行在不同的作業系統或不同的平台。為了節省開發時間。該程序可用JAVA開發而使用在各種不同作業系統的C或C++上。選用JAVA是因JAVA支援最多種的作業系統。



  • 情況二

主程式使用JAVA開發,而擴充功能的套件卻是由其他程式語言寫出為了避免重新買入只是由JAVA寫出的同功能套件而增加成本。所以使用JAVA調用該套件。


  • 情況三

為了增加JAVA程式語言在處理某特定程序時的效率,使用JNI調用特殊程序。如直接C++寫出的繪圖套件或是跑多CPU的程式。(JAVA 1.7版前無支援多核心處理。)或是特定演算法。


  • 情況四

執行某些JAVA程式語言無法處理的程序。


  • 情況五

藉由JNI直接使用CPU和記憶體甚至是硬體資源。

在做系統整合性程式時,上述情況或多或少會遇到。或是想把不同的程式結合在一起卻愛遇不同程式語言。基本上不同程式語言混寫有很多線程問題,以台灣的講法就是執行緒會出問題。我以前寫的時候真的常常遇到這問題。後來是靠國外有人寫好的套件解決的。今天先寫簡介改天有空再寫教學。


方法有很多種不過幾乎都是基於JNI以下是JNI的介紹
JNI是Java Native Interface的缩写,中文为JAVA本地调用。从Java1.1开始,Java Native Interface(JNI)标准成为java平台的一部分,它允许Java代码和其他语言写的代码进行交互。JNI一开始是为了本地已编译语言,尤其是C和C++而设计的,但是它并不妨碍你使用其他语言,只要调用约定受支持就可以了。使用java与本地已编译的代码交互,通常会丧失平台可移植性。但是,有些情况下这样做是可以接受的,甚至是必须的,比如,使用一些旧的库,与硬件、操作系统进行交互,或者为了提高程序的性能。JNI标准至少保证本地代码能工作在任何Java虚拟机实现下。

JAVA和調用的程式語言處於不同的執行緒,需要自行寫例外處理或是特殊編程。所以在執行複雜程序時常會出問題。遇到很多情況我也不知該怎麼處理。所以我就用OOJNI和JNB的軟件。


JNBridge
微軟的.net套件可以和JAVA互相使用,蠻好用的軟體只是比較貴。

Bridge anything Java to .NET
Bridge anything .NET to Java
Anywhere

Connect JMS to anything .NET
Connect JMS to BizTalk Server

JNBridge provides plug & play adapters that allow you to exchange messages betweenBizTalk Server or a .NET application and a JMS messaging infrastructure. The adaptersjust work right out of the box.

Enterprise-class interoperability
World-class integration

Do you have .NET-based and Java-based components that you need to haveinteroperate or heterogeneous applications that you need to integrateEnterprises around the world have successfully used JNBridge'ssolutions to meet their interoperability needs. Is one of these scenarios yours?






OOJNI

可以讓JAVA調用VB、 C++、  C# 、Delphi

What is OOJNI? Object Oriented Java Native Interface (OOJNI) is a set of tool (Add-In) for Microsoft Visual Studio 7.1 or 6.0 or MS VS.NET (and in the future for MS VS 6.0 and MS VS .NET, Borland C++, UNIX and Linux OS- each Edition will be for Java 32 and 64Bits) which generates C++ wrappers of JNI code for Java classes and a library of helpers that simplify programming to the Java Native Interface (JNI) with C++. With OOJNI Add-In C++ Programmer can select Java classes in byte code and generate C++ JNI "proxies", which have the structure like the java class. Its functions include all necessary JNI code to access fields and methods of the java class. Helper library include classes that simplify working with the JNI data types (string, array, etc.) as well as with JVM interface and exception handling. The main advantage of OOJNI tool over others is that OOJNI Add-In generates C++ code without use of java reflection. What is Java ByteCode Viewer? This is a simple tool that reads, parses and shows byte code as a tree. It may be suitable for studying and debugging Java byte code. Byte Code Viewer can load class files (*.class), JAR and ZIP archives with byte code. The content of Archive File is loaded to the left pane. On select a class name in the class list the tool shows Byte Code Tree in the right pane. The byte code tree is a structured map of the byte code file. It shows only data that stored in the file. 



還有許多軟件但個人覺得這兩個是比較好用的,市面上大部分都是JAVA和微軟系列語言的調用居多。JAVA在台灣JNI很少人用,但是如果是開發Android的人就會經常使用JNI。


arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()