0

I am absolutely new to java and am referring to a program energy2d. Its source code is here.

It is run as an embeded applet(see at the website link in github, as I am not allowed to post more then one url) (functions with default locale for the browser) or on the command line:

java -jar /home/ntu/Downloads/energy2d.jar

And there are some commands for it, -I call them control interfaces further on, I guess they are some public methods but do not know the exact term for them - that control the program at runtime. see website manual scripts.html

One can use them from inside the program in a embedded shell or you can see how they are called in the source of the website from java script at the embedded applet.

I do not understand that well, it should just demonstrate that for example the string "reload" as a occurrence of the control interfaces is used in the page*s source. To my current knowledge I can not make out where they are defined; it is at github Scripter2D.java#L55 where I loose track within the java-code. (do not know if this helps)

Now, what I want is to call these control interfaces from within an outside script. Let's say a bash script; well in the end I want it run python.

something like command line pseudo code:

snippet start

java -jar /home/ntu/Downloads/energy2d.jar #to start the application
java -do_to_running_program energy2d.jar -public_control_function load path/new_config.xml#to load another configuration file
java -_do_to_running_program -public_control_function run #to restart

snippet end

Questions: -how is that achievable? -If it is not possible: what would be a good practice to change the java code in order to have this working?

Any hints will be thanked.

1 Answer 1

0

Assumption: by 'java script', you actually mean that you want to provide some service-interface to your java applet which is accessible by other processes (local or remote), and that this service-interface could be driven by a script.

If so, then yes, it's achievable -- file watching and jmx come to mind. Your biggest concern should be security (eg, there's this: https://www.rapid7.com/db/modules/exploit/multi/browser/java_jre17_jmxbean). Having your applet expose such an interface is ok for testing I guess (but unit testing is almost always better); however, I strongly advise against exposing such interfaces in the final applet.

3
  • Thanks. Well, I try to be the most precise: The case it that I am only the user of this program, I am not the author. The author is running the same code on the website and as well offers it as a jar file. The applet is running on a website, yes, but I want it running as a local binary. link given these functions are already implemented as "service-interface" as the site states: "The Scripting User Interface (SUI) of Energy2D allows it to communicate with external programs such as JavaScript." what would then be the calling syntax? Commented Jul 25, 2014 at 21:26
  • oh ok. Just from grepping through the energy2d applet source, it appears it will execute any script supplied with the 'script' parameter to the applet. It retrieves this parameter using docs.oracle.com/javase/7/docs/api/java/applet/… Commented Jul 25, 2014 at 21:52
  • Thanks for that. Given the non-web side of the application, what be the effort to implement such a jmx-service-interfaces-mechanism to the existing code? Let's say there might be a jmx-pyhton lib around for that. - Anyway I searched the internet and rarely found something, some tutorial or the like, on that... Commented Jul 26, 2014 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.