CLI communication with already running Java application? - java

When starting a application, one can pass parameters to the application. But how can one pass parameters to a already running (Java) application / how can I handle such cases in my Java program?
In other words: How can I communicate from a .bat file / CLI processes with a already running Java application? Note that both things (CLI stuff and Java application) are my own applications and I can adapt the source code - I just don't know how ;-)

I prefer using socket for cross platform IPC, with help of Apache thrift . You can implement RPC method to use from CLI utility.

Related

Communication between java spring server and python applications

I designed my java spring application to run a couple of python programs on same server and communicate with them. I run them with ProcessBuilder and communicate via InputStream/OutputStream.
Now I want to achieve that when I restart or shut down my java application, python apps didnt close. I can't get Process object by PID. With ProcessHandler object I can't get input/output streams. It seems that i should use some other mechanism of IPC. So the questions are:
How can I run external applications from java so they wouldn't close when java app restarts?
How can I achieve communication between java and python applications without having Process object?
Thanks in advance, sorry for poor language :)
I give some suggestion on our project experience:
In single server, use docker-compose to run/stop app no matter using java or python. In multi-server,they will be deployed in Istio.
use Restful protocol to communicate between them.

Calling Python machine learning service from Java as an OS process or micro service via REST

I am building a web application for business management as a side project and i face an architecture problem.
My application will be an Angular web client communicating with a kotlin/java spring back-end via REST. One of the modules of the application will be time series forecasting of sales/orders, and because of the ease of development and the piles of documentation that exists online, i want to build that module in python. That module will generate dynamic html plots that i want to serve to the client. So my question is, it would be better if i do the python part as a stand alone rest micro service with Flask or it's ok to just put the python code inside the java project and call it using ProcessBuilder? Thanks in advance :)
My view will be to create a microservice with Python Flask with certain REST endpoints for obtaining the results and let java application interact with python based microservice for machine learning. The main advantage with this approach will be the separation of concern and deployment will be independent and you can leverage the benefits of microservice architecture.
Although it is also possible to bundle python code inside java or you can use jython, any changes in either in java code or in python code will add extra overhead for deployment. Bundling additional non java code will be another overhead for different OS systems like Windows, Mac and Linux.
You can check the following links for reference.
https://www.datacamp.com/community/tutorials/machine-learning-models-api-python

how to use java code from .net desktop application?

I want to Use Some Java Code From the WCF Service. Basically I need to intreact with the java application from the .net so how can I make it out for that? Any guidance for that?
I was just wondering that how can i call java code from my .net desktop application? Do I need to create .exe file of my java poject or jar? How would I invoke that java project from my .net desktop application?
Like some code in .net desktopp application will call
void startprocessing ();
code written in java application
Let me Clear the Things What i want to implement..
I have one desktop appplication of windows and I want to integrate my speech recgnition facility in that application which is in java. What I want is to exchange the audio data as binary and some strings from .net application to my java application so I can process on that binary data to convert wav file and etc and recginze it..that is just completed ..but what I need to know is how to send those strings and some binary data to java application and just invoke that java application ?? Do I need to 'use'(?) wcf or other service ?
Going out on a limb here, sounds like you java app needs to expose the method you want to call via a web-service. That's of course assuming you have control over that in terms of the java app you're interacting with. Not sure though you can access that method simply by compiling your java app to native.
You can take a look at JNBridge, which provides interop possibilities between Java and .NET. However, as another poster has suggested, exposing the functionality through a web service is probably a better solution.
A quick Google search will give you plenty of information on how to create web services in Java, but for starters you can take a look at: http://docs.oracle.com/javaee/6/tutorial/doc/bnayl.html
I have Successfully done that with the axis 2 webservice with tomcat apache server with the following link..its too easy .i really got succeeded
http://blog.sencide.com/2011/06/create-web-service-using-apache-axis2.html

Java daemon under Linux: Choices?

I have a console application (written in Java), which should run on a Linux machine until it is stopped.
Logging is done by the application itself.
The application needs to be stopped whenever a new version is available (i. e. I login, stop the application, copy the new JAR file, and then launch it again).
What are the options for implementing this, apart from those specified below?
Known ways to do it:
1) Tanuki service wrapper
2) nohup java -jar myapp-1.32.jar &
I use Java Service Wrapper, but you already mentioned it. I think it should suit your needs.
Apache Commons Daemon is also popular: http://commons.apache.org/daemon/, but I never used it.
I'm using this startup script: http://shrubbery.homeip.net/c/display/W/Java+Daemon+Startup+Script
[Changed domain name - by wiki owner]
Some modern Linux distributions have switched to upstart. That's a daeomon starting and stopping all the other services. I'd definitely look into that. Since it solves some tricky problems with production ready start scripts. The downside is that it has no java specific functionality.
There also the apache commons deamons http://commons.apache.org/proper/commons-daemon/jsvc.html
Jsvc is a set of libraries and applications for making Java applications run on UNIX more easily.
Jsvc allows the application (e.g. Tomcat) to perform some privileged operations as root (e.g. bind to a port < 1024), and then switch identity to a non-privileged user.

Attach a clojure / scala repl to a running JVM

I have a java web application running under tomcat in a Sun java 6 JVM. Is there a way to attach a scala or clojure REPL to the running JVM ?
Once the webapp is up and running, the context in which the calls are to be made is already setup in the running VM. Hence, this can be really helpful in invoking arbitrary java method calls for incremental, exploratory development and for debugging.
Copied over the answer from the other question as per your request:
liverepl: Connect a Clojure REPL to running Java or Clojure processes without any special setup
From the website:
Start a Clojure REPL connected to any running Java or Clojure process
without needing the process to be setup in any special way beforehand.
Now supports connecting to Tomcat web applications.
You can use the repl to run code, inspect variables, and
redefine Clojure functions.
https://github.com/djpowell/liverepl
There's no way to attach a REPL to an already-running JVM, so you need to think about the problem backwards...
Start the REPL on the server, either when the program is launched or in response to a inbound client connection (using e.g. Telnet).
There's a good example here: http://blog.homecloud.ca/2010/03/scripster-interactive-scala-repl-using.html
You could also host an Interpreter instance in your server, then expose a web interface. This is the approach taken by http://www.simplyscala.com/
If you're thinking of debugging, then you'd be better served by this answer: Drop into interpreter during arbitrary scala code location
You could use this:
https://github.com/wirde/swank-inject
Allows you attach a Clojure repl to a running java process (with remote debugging enabled).
You are also able to specify a number of classes (singletons) for which instances will be found and bound to a symbol available in the repl.
For Scala REPL connecting to other JVM, take a look at Scalive.

Categories