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.
Related
This question already has answers here:
Running Python scripts in Java
(1 answer)
Call "interactive" Perl script from Java
(3 answers)
Invoking bash from Java interactively
(2 answers)
How can I exec an interactive shell from Jython?
(1 answer)
Closed 4 years ago.
What I want to do is, I have a semantic parser written in Java, and this semantic parser will output one-liner code in Python (string). And I want to make this consecutively. Methods I searched are runtime.exec or Jython where I can run the entire script. But I want to write code line by line and see the result after each line.
So let's say my Java program returned "import pandas." Then it will run that line in python. And then user makes another input and Java returned "pandas.read.csv('somefile.csv')". Then based on my previous call "import pandas", I will run the next line of code in Python script. I want to do this consecutively, since my semantic parser makes a one-liner code in Python based on the user input.
Ideally I would have Java program run Python interpreter and feed each code one by one and see the reuslt. But I'm not entirely sure if this is a feasible way to do this. Obvious solution would be to add line by line in a Python script and just run the entire script. But this would waste a lot of time. So if there is any good way to do this, please share with me. Thank you.
The jep project uses JNI to embed a python interpreter within the java process. The eval method of the Jep class is specifically intended to allow you to run python line by line.
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
This question already has answers here:
How to read console ouput
(2 answers)
Closed 8 years ago.
My grails app has an external java library which I developed. I want my grails app to be able to display my java library system.out statements (console output). How do I go about doing that?
I would rather not have to write it out to a file then read it in grails. There must be a better way of doing this.
**I want grails to display these to a text box as the happen(In a browser while its running(so the user can see))
Afer trying several of my own ways I have to settle for this way which I will post here. Thanks #Shaunak for your help and understanding.
**How I solved it.
In my java library I created a global class which all the System.outs will be wrote to
writeSouts(String sout){
//store here in a global string and keep appending to it as needs be
}
Then in grails constantly call the java library method. and using Ajax write it out to the browser window.
Hope this helps anyone in the future who encounters the same problem.
Also it is not for testing but an integral part of my web app so that the user of the web app can was the java library is doing in the background.
Without much details on how exactly you are invoking the Java Library, I will assume here that it is just some code that writes to console, and you want to invoke and read it from inside Grails controller and send it back to HTML. Here's what I would suggest. Instead of including the Java Code as a library, create a command line utility out of it.
So your java program will be invoked for testing like so,
java MyLib -arg1 -arg2
This will should out put something like this on the command line:
> This is my nice output
Now to to invoke and read this from grails, you can use Groovy's External Process Management
and do something like this to invoke and read the output:
def process = "java MyLib -arg1 -arg2".execute()
def response = "Found text ${process.text}"
Your response var should now have value
Found Text This is my nice output
You can now use this to do what ever in a grails controller, like send it back to HTML..
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
This question already has answers here:
Please help me figure out what's wrong with this web proxy code
(6 answers)
Closed 7 years ago.
For example look at ninjavideo's divx player source. It is this:
src="http://127.0.0.1:64651/nv/47244"
How do they use the java applet to output the src as a divx readable file?
Source: http://beta.ninjavideo.net/video/47244
Warning: You will need to allow java applet
It's not "masked" it's just running as a local HTTP proxy. It downloads the file from a HttpURLConnection and listens locally for connections and serves up the video. Here's a (not so great) example: Please help me figure out what's wrong with this web proxy code