Best way for implementing JavaScript lib in Java WebApplication - javascript

I am an Android developer and I am new to java web development, so please apologize if my thought is wrong. In our web app project we have to compare images (GIF/PNG/JPEG) and have to show the result.
We got a javascript lib (Resemble.js) which will compare the images and will give the result.
Please help on implementing this lib to my web app project. As its a js lib we can implement it only in front end right? If so is this a correct way? Because we have all other process in backend. Or else how to use a js lib in backend
Or let me know the best way in implementing the same. We are using React.js for front-end.

To execute javascript you need a javascript engine. A java virtual machine is not designed to run javascript so short answer is: You should use the Resemble.js into your front-end browser's engine (or into a back-end server that process javascript like Node.js).
Long answer: There are implementation of JavaScript written in Java that you could use (I don't konw if supports HTML). Take a look at: How can I run JavaScript code at server side Java code?

Related

Electron GUI with C# backend

Use case
I've got an existing project developed in C# using WinForms with custom controls for the GUI. We are amazed by the approach to write GUIs using HTML/CSS/JS and we are looking for the best way to write a GUI for our desktop application using the above mentioned languages. We only need to support Windows devices.
My worries:
It doesn't take long to come across recommendations using electron-edge. While I am not so worried to get everything working, I am worried about:
Debugging my C# code (I still want to be able to start my whole application right from VS and debug it look I am used to it). I read that I would need to attach to the node.js application in order to debug my C# code afterwards. Since the whole program language is written in C# that sounds like a pain?
As far as I got edge will let it run as just one process. Can I consider the electron application as an own thread which would still run while my C# code is stuck somewhere?
My option:
I am still positive I want to write my desktop GUI with HTML/CSS/JS. What I considered instead of using electron-edge is writing an own electron application which does communicate with my C# backend using named pipes. I wonder if there are larger roadblocks why I wouldn't want to do this and use electron-edge instead?
My question:
I would like to get feedback for my two concerns mentioned above and I also would like to get input about my option to create the GUI as own electron process, so that I have two processes (GUI+Backend) when someone runs my application.
Electron.NET may be a option for you. You can write c# code with electron.
You can do it in many ways
1) COM. Create C# COM DLL. Create wrapper functions for the DLL using N-API (Native node module) or use FFI. You can access the functions from JS.
2) Create a .Net web server and include your functions as REST endpoints. From UI make http request to communicate (Clear separation of UI & BEnd)
You can checkout my github repo for a few alternatives to electron.
I think a most import question would be how your frontend interacts with the backend? Is there any notifications need push to the frontend?
WebSocket could be a good option for two ends communication.

Securing Javascript (server side?)

We have a project with a lot of proprietary calculations which we would rather not have downloadbable. Unfortunately the project was developed using tools that render the project in Javascript.
Is there any way to take browser based Javascript and put it on a server-side application that will render the HTML for the browser?
Have you looked at NodeJs? https://nodejs.org/en/
It's server side javascript

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). I will use the open-source Agar.io server called Ogar, which is implemented in 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. I have considered using Rhino, but it does not seem like it is possible to use in a browser. So, are there any way to let a Javascript implementation like Ogar use a Java library?
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.
the Agar.io server is a NodeJS server that expose a WebSocket API and the client solution need to communicate this way.
Using spring websocket client for example
have you seen Agar.io-bot ? its seems like the way they implement the BOT is javascript browser extension and communicate via the browser.
In common, Javascript and Java library communicate using Rest and Json, Java provide Rest API and Javascript send Json request to this API.
This is list of java library: for developing Java Rest API and working with JSON. I recommend using RESTEasy.

How to integrate AIML chat bot in Web Page

I have a web page where I just play with HTML, CSS and Javascript.
I have decided to create a Chat Bot there.
AIML seems like the way to go, and I already know how to write it.
Question is: After I have my bot.aiml file, what do I do with it?
I assume I need some sort of javascript function to interact with it.
If you only have access to HTML, CSS and JavaScript and not to some server-side technology, then you will need a JavaScript AIML interpreter.
A quick search turns up the following:
AIML Interpreter written in node.js
AIMLInterpreter is a module that allows you to parse AIML files and to find the correct answer to a given message.
aiml-high written in node.js. Built on aimlinterpreter.
aiml-high is a module that allows you to parse AIML files and to find the correct answer to a given message.
Surly2
a half-complete node.js AIML interpreter with a bad attitude.
Surly2 is a remake from the ground up of Surly using Node 5 and using as much asynchronicity as possible.
burly
Burly is a fork of Surly2
I too searched for the same but sadly i was not successful of creating my own bot..instead i found a website which will do exactly the same instead of we reinventing the cycle...
Create your account over here
http://www.pandorabots.com/botmaster/en/new-account
After signing in you have option of uploading your own AIML file and use the deafult AIML files and also Custom HTML and much more....
ChatterBean can help you to interpret the AIML files. From Alicebot.org,
ChatterBean is an AIML interpreter (also known as "Alicebot") written in pure Java.
For integration with Web, host a J2EE application with ChatterBean.
Since you already have understanding of chatbot, you can integrate it to your webpage by using php or j2ee (jsp being the easiest) which would send a request to the bot methods and return response.

how to set up a simple browser that support javascript?

I would like to setup a simple web browser that download a html page , parse it, generate a dom and execute the javascript code. I would like to know if there is a simple project(so not firefox which is good but too big to just understand this piece of logic) showing if it is the right way to handle this or someone to explain me if i am missing something. No particular language( but preferably be python, c#/c++/c ). I am stuck now at integrating the javascript engine, i don't know what to do.
Thx
I don't think its easy to pull off a javascript engine on your own. You could however use an open source engine (like WebKit's JS engine for example) and integrate it in your project.
More Infos:
http://www.webkit.org
google chrome is open source too with a neat javascript engine v8.
http://code.google.com/chromium/
http://code.google.com/p/v8/
another way could be nodejs. it's server side javascript using the v8 engine. so there is no rendering, just pure javascript. maybe thats enough if you do not need the rendering.
http://nodejs.org/
You might want to use the WebBrowser class from .NET for that purpose.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx

Categories

Resources