This question already has answers here:
Run Java class file from PHP script on a website
(5 answers)
Closed 8 years ago.
i have a PHP script which is provide to my one of the friend he is java developer.
that script is on class which is in java language.
i need to run that java program to complete my task. i need to run sum action once in day, and perform sum logical action and updated my data in database everyday.
Please let me know i to do it in php.
here is my java program code.
Run it the way you would run any command line program
var_dump(exec('java yourprogram'));
Perhaps in my opinion the best way would be as follows:
Run your java application on your server with another port (say port 1212)
If it is not needed outside your web server, better restrict the apache tomcat server not to expose port 1212 to anyone outside localhost (you can achieve it with iptables on linux)
Now from PHP, make CURL calls to your java application like http://localhost:1212/my_jar_code.jsp
Use it like web services, problem solved!
In this way your java code will be independent of your php code and you have complete compatibility and power on both java and php codes.
Related
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?
This question already has answers here:
Is it possible to run C source code from Java?
(4 answers)
Closed 7 years ago.
I want to make a Java app that uses the Razer Chroma SDK, but the Chroma SDK is in c++
Is there a way I can run c++ code from Java?
I must use Java for what I want to make.
I have almost no experience in c++, but I understand enough to get doing what I need.
EDIT:
This question is slightly different then others, because it is about a specific SDK, not about general c++ libraries. For this library I was able to use a simpler approach then learning to use things like JNI
You probably want to look into using JNI
The easiest way I found, and then one that doesn't require learning stuff like JNI:
Create a console application with commands that fire off what you need
In Java, launch the console application and redirect it's input and output streams so you can send it commands, and log it's output (see 12013910)
Have a command in the console application that you can pass a PID, and have the console application watch for when it closes, and then it will close itself. (This fixes having the console application not being closed if the Java application crashes and doesn't call the closing method(s))
This question already has answers here:
Run a command in a shell and keep running the command when you close the session
(9 answers)
Closed 7 years ago.
I have my spring boot application, I normally work with wars that I deploy on tomcat, but I want to try this way a little bit more.
My problem is that when I deploy it in a server, and I do
java -jar target/myproject.jar
Works pretty fine, but after a time without use, the shell gets disconnected and soon after it (I believe because the shell) the process stops.
Any idea how to deal with this?
I am using Debian.
Thanks.
Basically, create a .sh file and set it on /etc/init.d/YOURFILE.sh with the info of this post
Run a Java Application as a Service on Linux
Later just make a /etc/init.d/YOURFILE.sh start and thats it..
This question already has answers here:
Calling Python in Java?
(12 answers)
Closed 8 years ago.
I have a java web app where i need to use a simple web crawler to read html from webpages. I could not find any simple solution for this in java. But got a very simple python script that solve my problem. Now how to call that python script (.py) from my java class and also get the returned value from the python script .Thanks in advance .
First check out Calling Python in Java?
Another approach might be to call the python interpreter from the command line with a Java Process. See Java Process with Input/Output Stream and Call python script within java code (runtime.exec)
Can I start and stop IIS 6.0 application pools on one machine from within Java code running on another machine? If so, how?
Use Java's facility to execute another program and use the command line tool such as
appcmd stop apppool /apppool.nam
appcmd start apppool /apppool.nam
(see http://technet.microsoft.com/en-us/library/cc732742(WS.10).aspx)
I believe you can do it using WMI. Please take a look http://msdn.microsoft.com/en-us/library/ms525309(v=vs.90).aspx
and here: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/9041b0a5-c314-46d9-8f56-01506687f357.mspx?mfr=true
Or just google "iis wmi".
First find API you need and find a way to write JScript or VBScript that does what you need.
Then you have 2 ways.
Just execute script you have just done from java using Runtime.exec()
Use one of interoparability packages like JaWin, JIntegra or JInterop (or, probably others) to call the same code from java.