如何在Smalltalk中访问和使用Java库/软件包 [英] How to access and use Java library/package in Smalltalk

查看:117
本文介绍了如何在Smalltalk中访问和使用Java库/软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它在另一个Stackoverflow问题的评论中被提及,则可能可以从Smalltalk访问Java程序包.

It was mentioned in comments on another Stackoverflow question that it may be possible to access Java packages from Smalltalk.

但是,在搜索网络时,我找不到与此有关的任何信息.

However, I have not been able to find any information regarding this on searching the net.

在这方面的任何见识将受到高度赞赏.

Any insight in this regard will be highly appreciated.

推荐答案

基本上,存在三种在Smalltalk/X中(重新)使用Java代码的方法:

Essentially there three ways to (re)use Java code in Smalltalk/X:

  • 使用Victor建议的使用JNI的Java实现/端口绑定.虽然没有 移植到Smalltalk/X,这是由Johan Brichau等完成的. -- 搜索"JavaConnect",

  • Implement / port bindings to Java using JNI as Victor suggested. While not ported to Smalltalk/X, this has been done by Johan Brichau et al. - search for "JavaConnect",

然后有一个"Java Bridge"可以连接到远程JVM并在那里执行代码, 由eXept开发并在其产品中使用. AFAIK,这是专有的 软件包-您可以(或不可以)购买许可证.有关详细信息, 您可能要问eXept.

then there is a "Java Bridge" to connect to remote JVM and execute code there, developed and used by eXept in their products. AFAIK, this is a proprietary package - you may be able to purchase a license for it (or not). For details, you may want to ask eXept.

最后是stx:libjava,它是用于加载Java的Smalltalk/X API 直接将其分类为正在运行的Smalltalk/X运行时.

and finally, there's the stx:libjava which is a Smalltalk/X API to load Java classes directly into running Smalltalk/X runtime.

与往常一样,这些选项中的每一个都有其优点和缺点.我要去 专注于最后一个-stx:libjava-这是@tukan想到的一个.

Each of these options have their own pros and cons, as usual. I'm going to focus on the last one - stx:libjava - this is the one @tukan had in mind.

免责声明:我(重新)设计和(重新)实现了大部分stx:libjava,因此请 我有偏见时对盐的看法.

Disclaimer: I (re)designed and (re)implemented most of stx:libjava so take my views with grain of salt as I'm biased.

stx:libjava是一个允许将Java代码加载到Smalltalk/X中的软件包 环境并执行它.加载后,Java之间没有任何区别 代码和Java对象以及Smalltalk代码和Smalltalk对象-它们都存在 在同一运行时(如果您愿意,可以使用虚拟机).实际上,大多数 运行时不知道(也不在乎)给定的对象或方法是否为 实际上是Smalltalk或Java语言.运行时内部只有两个组件 区别-这是一个字节码解释器(因为Smalltalk/X字节码是 与Java字节码有很大不同)和JIT编译器前端(相同 原因).因此,执行之间在性能方面没有区别 Smalltalk或Java代码.

stx:libjava is a package that allows loading Java code into Smalltalk/X environment and execute it. Once loaded, there's no difference between Java code and Java objects and Smalltalk code and Smalltalk objects - they both live in the same runtime (virtual machine if you prefer). In fact, most of the runtime does not know (and does not care) whether given object or method is actually a Smalltalk or Java one. There are only two components inside the runtime that distinguish - that's a bytecode interpreter (since Smalltalk/X bytecode is very different from Java bytecode) and JIT-compiler frontend (for the very same reason). Because of that there's no difference performance-wise between executing Smalltalk or Java code.

这是使用从Java开始以Java实现的SAXON XSLT处理器的示例 Smalltalk/X:

Here's an example of using SAXON XSLT processor implemented in Java from Smalltalk/X:

[
    config := JAVA net sf saxon Configuration new.
    config setAllNodesUntyped: true.
    factory := JAVA net sf saxon TransformerFactoryImpl new: config.
    stylesheet := factory newTemplates:
        (JAVA javax xml transform stream StreamSource new:
            (JAVA java io File new: 'cd.xsl')).
    input :=
        (JAVA javax xml transform stream StreamSource new:
            (JAVA java io File new: 'cd.xml')).
    output :=
        (JAVA javax xml transform stream StreamResult new:
            (JAVA java io File new: 'cd.html')).
    transformer := stylesheet newTransformer.
    transformer transform: input to: output.
] on: JAVA java io IOException do:[:ex|
    Transcript showCR:'I/O error: ', ex getMessage.
    ex printStackTrace.
] on: JAVA javax xml transform TransformerException  do:[:ex|
    Transcript showCR:'Transform error: ', ex getMessage.
    ex printStackTrace.
].

更多参考

下面的资源可能会让您更好地了解它的含义:

Further references

Following resources may give you better idea what is it about:

  • On the integration of Smalltalk and Java https://www.sciencedirect.com/science/article/pii/S0167642313002839?via%3Dihub

使用Java进行运行时代码更新-使用STX:LIBJAVA的探索 https://pdfs.semanticscholara.a4dbd45d73d7b4d7d7d ?_ga = 2.80940304.648336672.1556837288-1980277485.1556837288

Towards a Runtime Code Update in Java - an exploration using STX:LIBJAVA https://pdfs.semanticscholar.org/d7da/968e4ab36d6deca51bd45b9bbb70e73a2afd.pdf?_ga=2.80940304.648336672.1556837288-1980277485.1556837288

快速浏览,展示如何开发简单的"Hello World!"应用 使用Smalltalk/X和Java http://swing.fit.cvut .cz/projects/stx/doc/online/english/programming/java-helloworld.html

A quick tour showing how to develop a simple "Hello World!" application using Smalltalk/X and Java http://swing.fit.cvut.cz/projects/stx/doc/online/english/programming/java-helloworld.html

STX:LIBJAVA中的动态代码更新 https://www.youtube.com/watch?v=p3J554BNEz8

Dynamic Code Update In STX:LIBJAVA https://www.youtube.com/watch?v=p3J554BNEz8

玩Java https://youtu.be/p21z3bAt7b0

这篇关于如何在Smalltalk中访问和使用Java库/软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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