Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

How to call a Java Remote Method from shell script

 
Ranch Hand
Posts: 98
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to create an entry point in my java application to call a method by a shell script passing some params.

I was wondering if is possible to do it via RMI or it is needed in that case for the client to be another java app?

I have thought as different choise  create a MBean and use JMX through some terminal emulator (such as: jmxterm).

Any other idea? By the way, I am using JavaSE

Thanks in advance
 
Marshal
Posts: 68909
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain more. Why would you want to be remote in the first place? What is wrong with Runtime#execute()?
 
Saloon Keeper
Posts: 6380
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the Java code is permanently running (as some sort of server), and you need to trigger something from the outside? You could open a server socket, which a shell script should be able to connect to via netcat (nc).
 
Saloon Keeper
Posts: 21966
149
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RMI requires that not only both client and server apps be Java, but also that they be compatible versions of Java. That's because RMI uses Java Serialization and Java Serialization changes between different Java versions according to no known rules.

You should be less concerned about how to "call a Java Remote Method" than you are about "how to invoke a (remote) service". The real goal is to get something done and/or retrieve information.

These days, probably the most common way to invoke a remote service - possibly even a microservice - is via Web Services. In such a case, the server provides an HTTP API and the client can be written in any language. Data transferred to/from the server is in text form, usually JSON, YAML or SOAP. It's easy for a shell script to invoke web services using curl or wget.
 
Alfonso Sanz
Ranch Hand
Posts: 98
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick answers

The idea is for a Swing application to be invoked from a script with a string as param ("remote" is so to speak. In fact must be called from same computer) to update one entry of a JTable asynchronously (No returns).

Probably as Tim Holloway said, the most elegant approach is a microservice, but I don't want to need tens of jars to solve this "small" issue.

This is because I thought of JMX or RMI to avoid so many dependencies.

Still recomending me a microservice? Can I run a microservice without Web Server? (sorry for my ignorance)

Anywhere to get a short manual?

Thank you all!!
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic