I need to run a single java program (which will change the content of some text files) on my new website. What's the easiest way to do that for example using php code?
Do I need to install JVM or any other software in order for this to work?
Please guide on how to do this step by step if possible.
You have to install a Java Runtime Environment (JRE) on your server to be able to run a java program.
http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
To execute a java program in php, you can simply use the exec() function :
exec("java -jar yourProgram.jar");
http://php.net/manual/en/function.exec.php
Related
I can run kubectl get secret/rabbitmq-expressmode -n expressmode in shell successfully.
However when I try to run it in java with either ProcessBuilder or Runtime.getRuntime().exec, the error:
Error from server (BadRequest): the server rejected our request for an unknown reason
is thrown out.
What's the possible reason?
Best approach would be to use official java client library.
Installation is pretty easy, and code examples shows you how to use it.
If the official one does not meet your requirements, there are also community-maintained client libraries:
Java (OSGi)
Java (Fabric8, OSGi)
Java
I had same issue but resolved by programmatically creating bash file containing kubectl... command I was trying to execute directly.
For example, create bash file and put your kubectl command there (i.e.: some-file.sh). Then try then executing it in bash process running within your java code (bash some-file.sh).
I am having some serious trouble installing and running Jython. I am completely new to how jython runs, so I am pretty lost. I have downloaded Jython 2.5.3 and java jre 1.8.0_25. I believe I have succesfully run the jython.jar file using this command in cmd:
C:\java\jre1.8.0_25\bin\java -jar C:\jython2.5.3\jython.jar
I have beginner-intermediate (closer to beginner) knowledge of programming in jython, but that is on a computer with jython already installed. My main problem is being able to run jython so I can see the actual function/program area where you would type out your functions then run them. I appreciate any help someone can give.
That command is exactly how you run Jython, and without providing any additional arguments, the Jython interpreter will start (where you can type out functions and run them).
If you want to run Jython with a single command, there should be a jython.bat file located somewhere under the Jython installation directory. Jython does not have a true executable because it is run through Java. The jython.bat file is the closest you'll get to an executable because it is a batch script which runs the jython.jar file using a command nearly identical to yours with Java. jython.bat should be located at one of the following locations:
C:\jython2.5.3\jython.bat
C:\jython2.5.3\bin\jython.bat
NOTE: The jython.bat file requires a standard Java installation.
I have done image processing in MATLAB and build my GUI in Java. I want to integrate MATLAB into Java. I want to use MATLAB Builder for this purpose. I want also to use neural network for classification. There are some excel files also. Is it possible that this code will be integrated in Java?
My other question is that I want used MATLAB BuilderJA to know how it works. When I type java -version command, it gave me this error.
??? Attempt to execute SCRIPT java as a function:
C:\Program Files\MATLAB\R2009b\toolbox\matlab\general\java.m
C:\Program Files\Java\jdk1.6.0_21
When I use build command it gave me this error.
'javac' is not recognized as an internal or external command,
operable program or batch file.
Error: An error occurred while shelling out to javac (error code = 1).
Unable to build executable.
I have JDK installed. The path is C:\Program Files\Java\jdk1.6.0_21. I am using R2009b version
I want to run my code in Java, but I do not know how to fix this error. Can any one tell me how to resolve this error?
The first error message which you get when you type java -version is a bit misleading; instead of
java -version
you need to say
!java -version
since you want to call an external program and not a MATLAB script or function. As stated in the comments by Amro this will only work if the directory containing java.exe is on your path. See Running External Programs in the MATLAB help for more info.
The error message you get comes from the fact that
there happens to be a file java.m and MATLAB thinks you are trying to call this file
that file only contains comments, since java is actually a sort of keyword in MATLAB, see doc java.
MATLAB realizes that you are not using the keyword in its correct form (which would be to call java.something to create an object of class something) since you give a parameter
MATLAB ends up telling you in a strange way that java doesn't accept parameters (even though java.m does not contain the script, only its documentation)
Note that if you don't want to add the directory containing java.exe and javac.exe to the path, you could also try calling them with their full path name:
!C:\Program Files\Java\jdk1.6.0_21\blablabla\bin\javac.exe
I encountered some problems with the shell function in php. I want to execute a java program on the server by running a php function on a php webpage.
The java program writes some chars to a local file on the server.
test.php
<?php
$WshShell = new COM("WScript.Shell");
$cmd = ' "C:\\Program Files\\Java\\jdk1.6.0_14\\bin\\java" Importer 1 2 updated.txt 7';
$WshShell->exec($cmd);
echo "okay";
?>
When test.php is executed via command line on the server,
c:\php test.php
the java program runs.
However, if I executed it through web browser, the Java program is not called.
http://127.0.0.1/test.php
Is it because the Apache user is not allowed to use the command line functionality on windows?
System configuration:
Microsoft windows XP, Professional X64 edition, Version 2003, service pack 2
PHP version: 5.2.6.6
Apache 2.2
IIS 6
Why don't you use ordinary PHP 'exec' function?
i found the solution here
Calling MySQL exe using PHP exec doesn't work
it is not the OS problem, but "quotes" problem.
What error do you got ?
Not really knowing php i do however have a question:
You dont fully qualify the file that the Java program needs to update, you sure its not written but under some directory where your php server is installed,
Your problem could be due to PHP running with Apache under "safe_mode"...You can check this in your php.ini file.
I want to start nutch from Java. How can I start cygwin from a Java program?
First of all you have to set the bash.exe to environment variable so this line will start bash.
Runtime rt= Runtime().getRuntime().execute("bash");
Rather than use Java to start Cygwin in order to invoke nutch you should probably look into integrating Nutch directly with your Java app. There's some documentation here:
"While the Nutch web app is a great way to get started with search, most projects using Nutch require the search function to be more tightly integrated with their application. There are various ways to achieve this, depending on the application. The two ways we'll look at here are using the Nutch API and using the OpenSearch API."
If you are trying to run a binary that requires the cygwin1.dll (which includes most commands you can execute from the cygwin bash shell) then you can run it by specifying the cygwin\bin directory in the path environment variable like this:
Process p = Runtime.getRuntime().exec(
"C:/path/to/cygwin/binary.exe", new String[] { "PATH=C:\\cygwin\\bin" });
This assumes you installed cygwin in C:\cygwin
You can use any Cygwin program without passing thru Cygwin, just like any regular Windows Console Application. Take a look at the Cygwin\bin\ dir. You may even bring the programs you want to your app dir, as long as you bring a copy of CYGWIN1.DLL as well.
A more interesting, more clever thing to do, would be starting Nutch from Cygwin or using a real Linux/Unix system.