Execute a jar with Delphi - java

I want to know if there is some way to execute a jar console application by Delphi and give commands for it like a cmd.
Actually I have a java application that I don't have the source anymore and it's limited to only two commands by console, so I want to create a delphi application and it will have buttons instead console commands.
There is a way to do this?

Related

how run java app on background without aid of bash tools etc

Say you have some cli app, which calculates something for very long and outputs it into file. I want to run it as a normal app, say java -jar ..., get control immediately back to shell (let it be bash/... or windows terminal), while the actual java app still runs on background.
In linux I know about & or better nohup java -jar ... &>/dev/null &, I'm not asking about that. I'm asking how to get this 'nohup' behavior, in multiplatform way without using nohup etc.
I never did that, but I guess I could start some launcher jar, run yet another one somehow in detached way (no idea how) and then quit. Is it somehow attainable within single jar?

Call a dockerized python script from another dockerized java application?

I need to create a Java application which sends some input parameters to a python script and sends some output back to my java application.
I cannot run the script in my java code using jython Or similar things as the python scripts are build on demand and I may need to add new scripts every now and then. So this should not impact my java app.
My java application will be running on a container and based on a few condition check it might have to select 1 of the py scripts from suppose 100 scripts and run it. And again the condition later on may change and a different script has to run at that time
I went through many websites and tutorials on the net but did not find anything relevant.
Has someone tried anything similar?

How to call MATLAB program from the java application

I am trying to call matlab executable file from java application
i am try 2 option:
Process p=new ProcessBuilder("C:\\Users\\Dexter\\Documents\\MATLAB\\Project.exe").start();
Process p= Runtime.getRuntime().exec("C:\\Users\\Dexter\\Documents\\MATLAB\\Project.exe");
... these 2 options are work properly for another application like chrome, eclipse, et cetera
pls suggest the solution
I suppose that you are trying to run an executable exported from Matlab, within Java. I am not sure that this is going to work...
What you can do is to use the matlabcontrol library in order to open a session with Matlab and then you will be able to run Matlab commands directly, from Java, or run a Matlab script from Java, by giving some inputs and taking back the result from Matlab. I have created a server which does all the aforementioned, in Java, and using matlabcontrol library to connect with Matlab. You can find it here:
Connect Java with Matlab
Let me know if you need any further clarification.

How to launch a .jar that needs elevated privileges?

I have a little .jar that executes a simple system administration task and so it needs to be run with elevated privilege. I've been researching this for hours and now know that it can be done in three ways:
1) ran from an elevated cmd prompt
2) convert the .jar to .exe and bundle it with a manifest file
3) use another .jar to launch my .jar and ask for permission.
Option 1) won't work for me because this will need to be deployed to other users that won't know how to do this. Option 2) isn't ideal because I chose to write this app in Java for its portability. This will likely be run on different systems and Java seems the most compatible. So that leaves Option 3) and is where my question comes in. I can't seem to sift through the multitude of info out there on how to accomplish creating a wrapper for my app. With my specs in mind what do you all recommend for creating a wrapper .jar that will prompt the user to allow my .jar to run? Thanks
On Windows, it is possible to run a Java application either as a desktop application, or as a Windows Service in the background. In the case of a Service, the Wrapper needs to be able to be installed, removed, started, stopped, have its status queried, etc. Depending on whether the application has a GUI or is meant to be run in a command window also determines how it will be run.
On Windows systems, the most way of launching the Wrapper is to make use of dedicated batch files to perform each action of controlling the Wrapper. This makes it possible for the end user to double click on the batch file icons or set up links in menus, just have a look if you have the java runtime env.
Nice tutorial: http://wrapper.tanukisoftware.com/doc/english/qna-service.html
Here it has some other possibilities, using Dedicated Batch File, Command Based Batch File or Standalone Binary : http://wrapper.tanukisoftware.com/doc/english/launch-win.html#dedicated
Think you can do this with .bat file. Make sure you have java runtime env, so that you can execute jar file using java -jar command.
If your looking to force the user to use elevated permissions then pure Java isn't going to cut it. I suggest you write native code and use the Java Native Interface (JNI)

How to call c++ functionality from java

I have a Java program that is mostly GUI and it shows data that is written to an xml file from a c++ command line tool. Now I want to add a button to the java program to refresh the data. This means that my program has to call the c++ functionality.
Is the best way to just call the program from java through a system call?
The c++ program will be compiled for mac os and windows and should always be in the same directory as the java program.
I would like to generate an executable can the c program be stored inside the jar and called from my program?
If you have access to the code and want an 'interactive' experience with the external program (e.g., make call, get results, make additional calls), investigate JNI, which allows you to call C or C++ code from a Java application by including & linking JNI juice to your C or C++ app with .
See:
http://en.wikipedia.org/wiki/Java_Native_Interface
http://www.acm.org/crossroads/xrds4-2/jni.html
If you really just need a "launch app and get results" sort of solution, check out Runtime.exec(), which lets you launch an external program & capture its output.
See:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1
http://www.rgagnon.com/javadetails/java-0014.html
Assuming no better communication method is available (SOAP, ICE, Sockets, etc), I'd call the executable using Runtime.exec(). JNI can be used to interface directly, but I wouldn't recommended it. No you can't put an executable in the jar. Well you can, but you can't run it, since the shell doesn't know how to run it.
You may also want to look at the Java Native Access API (JNA).
To answer your final question, you can't run an executable from within your jar.
However, you can store it within your jar and extract it to a temporary directory/file prior to running it (check for its presence the first time and extract if necessary). This will simplify your distribution somewhat, in that you only have the jar to distribute, and ensures that you're running an executable that matches your jarred Java code.

Categories