This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Execute external program from Java
Is it possible to Run a php script from a java class. My project is a struts2 frame work web application. Its purely a java webapp We use a php script to run some daily cron jobs. It was written in php by an ex-employee. Is there a way to run the php script from the javaclass?
Since you're essentially running a command line script, you could use Runtime.getRuntime().exec. Here's a page with a plethora of examples: http://www.rgagnon.com/javadetails/java-0014.html.
If the PHP script is externalized as a web page, you could use Java's URLConnection to call the page so it runs. Documentation: http://download.oracle.com/javase/tutorial/networking/urls/readingWriting.html
Related
This question already has answers here:
Execute Jar file from C sharp code and get return value
(2 answers)
Closed 7 years ago.
I have a c# application and I have a .jar file that I have created. I want to call from c# application, my jar file, I want to call a method in the jar file. I try to use JNI but I can't call jar file.
There is a mode to do this?
Your main problem is the lanuage incomaptabilities
As far as i understand there is no direct way that Java (jar) and c# assembles can talk to each other.
Question is what does the jar file do ? and can the same be done using c#
If not then you are going to have to create a java application using somethign like Netbeans to act as a kind of middle man
Then when the c# application does a function call the call gets serialised into a file
The java app should then look for the file (in a thread or something) pulling the data and writing the response data to the file
While asp.net looks for changes in the file and pulls the data back from the file once java has written
There are other options such as web service and TCP IP socket server to communicate
But Long story short there is no clear cut way as far as i am aware of that there is not clear cut way of making java and .net talk to each other .
A quick google search did bring up http://www.ikvm.net/userguide/tutorial.html[^] which seems to be promising.
Hope this helps
I want to run a JRuby script in my Java application in Android.
javax.script is not included in Android. You can try to import the package manually, but when you try to obtain the JRuby engine, it returns null.
Apache BSF can't load the engine either. You get an error related to "privileged exception: cannot load class file" - I imagine that Android doesn't allow this sort of loading, so you can't dynamically load JRuby with BSF.
SL4A doesn't make any sense at all. Besides the fact that they don't have clear instructions on how to use it for running JRuby, the last time it was updated was like 4 years ago.
Ruboto is used for writing Android applications with Ruby. That's not what I want. I just want to run a Ruby snippet in my Java application.
Is there any way you can run JRuby scripts in a Java application in Android? Are there clear instructions anywhere?
Apparently, you can use the --java flag with jrubyc to generate java source code from jruby code.
If you don't have an absolute requirement to retain the jruby script at runtime, I'd do that, and then put the java code into the Android app.
Of course, you'll still need the jruby jar file in your Android app.
See https://github.com/jruby/jruby/wiki/GeneratingJavaClasses#user-content-generating-java-classes-ahead-of-time
This question already has answers here:
How to create a windows service from java app
(20 answers)
Closed 8 years ago.
I have created a jar file in java , the problem is when ever the system gets restart i need to manually run the jar file so i have decided to convert my jar file to a windows service . if anyone knows please help me out
The Java Service Wrapper makes it possible to install a Java Application as a Windows Service. Likewise, the scripts shipped with the Wrapper also make it very easy to install a Java Application as a Daemon process on UNIX systems.
The Wrapper correctly handles "user's log outs" under Windows, service dependencies, and the ability to run services which interact with the desktop.
Take a look at this
Java Service Wrapper
This question already has answers here:
Run Java class file from PHP script on a website
(5 answers)
Closed 9 years ago.
I created a JAR file and i need to call its methods from a Php file. I tried doing it with Php-java bridge but, it works only with sun java 6 which is an abandoned version. Also, i feel that using php-java bridge is not the best way of achieving what i want as it was updated ages ago. Are there any other methods which i can follow to call my java functions from a php file?
Execute your java programm from PHP with shell_exec(comand to start your java programm), it will return you the output from your java programm as string. http://www.php.net/manual/en/function.shell-exec.php
See Run Java class file from PHP script on a website.
In a nutshell: Use PHP's exec() function. It needs to be done very carefully, as described in the referenced issue, but if you do it right, (I've found) it can be a cleaner solution than the bridge method.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Redirect stdin and stdout in Java
I know how to execute shell commands in Java but how to do it so my application can write to its input and read from its output.
I think that you even explained the answer into your question.
When you are running external application from java either using Runtime.exec() or ProcessBuilder you can access standard output and standard input streams. User input stream to read what external application writes and output stream to send commands to external application.
But be careful. Some applications will not get your commands sent from java. For example command ssh in Unix system is designed to avoid its usage by non-human user (e.g. other application). It require to be executed from terminal for security reasons, so you cannot for example run ssh otherhost and then send user/password from java. If you need this you have to run the command via other command line utility named expect that simulates terminal and is driven by script.