简体   繁体   English

在Javascript中使用Java库

[英]Use Java Library in Javascript

I am planning a project where I will develop bots for Agar.io by using the NEAT algorithm, which is implemented in Java (this is called ANJI ). 我正在计划一个项目,我将使用NEAT算法为Agar.io开发机器人,该算法用Java实现(这称为ANJI )。 I will use the open-source Agar.io server called Ogar , which is implemented in Javascript. 我将使用名为Ogar的开源Agar.io服务器,它在Javascript中实现。 The Javascript implementation should communicate with the Java library to evolve the bots while the game is running, but I have no previous experience of how to make Java and Javascript communicate. Javascript实现应该与Java库通信以在游戏运行时进化机器人,但我以前没有如何使Java和Javascript通信的经验。 I have considered using Rhino, but it does not seem like it is possible to use in a browser. 我考虑过使用Rhino,但似乎不可能在浏览器中使用。 So, are there any way to let a Javascript implementation like Ogar use a Java library? 那么,有没有办法让像Ogar这样的Javascript实现使用Java库?

In common, Javascript and Java library communicate using Rest and Json, Java provide Rest API and Javascript send Json request to this API. 通常,Javascript和Java库使用Rest和Json进行通信,Java提供Rest API和Javascript将Json请求发送到此API。

This is list of java library: for developing Java Rest API and working with JSON . 这是java库的列表:用于开发Java Rest API和使用JSON I recommend using RESTEasy . 我建议使用RESTEasy

using the Rhino / Nashorm is not relevant in this case and as for performance focus its should be much hard to run nodeJS based application via Java JS engine. 在这种情况下使用Rhino / Nashorm是不相关的,对于性能焦点来说,通过Java JS引擎运行基于nodeJS的应用程序应该非常困难。

the Agar.io server is a NodeJS server that expose a WebSocket API and the client solution need to communicate this way. Agar.io服务器是一个NodeJS服务器,它公开WebSocket API,客户端解决方案需要以这种方式进行通信。

Using spring websocket client for example 例如,使用spring websocket客户端

have you seen Agar.io-bot ? 你看过Agar.io-bot吗? its seems like the way they implement the BOT is javascript browser extension and communicate via the browser. 看起来他们实现BOT的方式是javascript浏览器扩展并通过浏览器进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM