php exec() not refreshing Path environment variable - java

I upgraded my java jvm, and they changed the way they store the location of the jvm in the PATH environment variable.
It sticks "C:\ProgramData\Oracle\Java\javapath;" at the beginning of the Path variable.
Now, the problem is that when I do exec("java blah blah blah"), php can't find the new path. I get
"'java' is not recognized as an internal or external command, operable program or batch file."
It only works if I do the full path:
exec("c:\My\Path\To\Java\java blah blah blah")
When I do phpInfo(INFO_ENVIRONMENT), it shows the Path variable from before the change. Is it being cached somewhere? I read in other threads that restarting the server, or restarting Apache would help, but it doesn't seem to be working. I tried multiple restarts.
var_dump($_SERVER['PATH']), var_dump(getenv('PATH')) seem to show the NEW path. Why would the value in phpInfo be different? Is there a separate copy of the Path variable somewhere?
I have a development environment that I tested on Windows Vista, and I don't have this problem. When I test it on a windows 2008 environment, I get the problem.
I'm trying to avoid hard coding the path.

before the exec statement you can add the path to the path variable like so
putenv('PATH='.getenv('PATH').'path to java here');

Related

Apache nifi doesn't start

I've tried several times to run an Apache Nifi server, but it won't work. I'm using windows 8 and installed java version 8.
I get this error message:
'nifi-env.bat' is not recognized as an internal or external command, operable program or batch file.The JAVA_HOME environment variable is not defined correctly.Instead the PATH will be used to find the java executable.
Error Screenshot:
I've tried the solution to the following similar problem, but this did not help:
Nifi commands on windows
I've also tried what is explained in this video, but this did not work either:
How to Install Apache NiFi and run Simple Process
What should I do in order to run the nifi?
There seems to be a Java installation error, which is affecting the nifi-env.bat file. Problem will be solved if you create a virtual environment with java. The following link explains how to create a Java Virtual environment. This will also solve the problem with 'nifi-env.bat' is not recognized as an internal or external command as in that case nifi would only be able to be run within the virtual environment.
Try to troubleshoot the problem by reinstalling java, if the above doesn't work out.
I have pulling my hair off for this, but I discovered the directory which holds nifi, must have not spaces.
My folder's name was "apache nifi" and there I unzipped the download from apache nifi's website, but after one hour I realized the name could be the problem, and actually it was. I just changed folder's name from "apache nifi" to just "nifi" and voilá, it just runs.
Check if JAVA_HOME path is set properly.

Java application does not use the right PATH environment variable

I've been struggling to find a reason why my Java application does not use the default PATH environment variable. I need it to launch another program with ProcessBuilder. Right now I get "Cannot run program "..." error=2, No such file or directory", though I can run this program from the terminal. I'm using JDK 1.8, Netbeans 8.1, OS X.
Here's the output of System.out.println(System.getenv("PATH"));:
/usr/bin:/bin:/usr/sbin:/sbin
The actual value of PATH in the terminal (using echo $PATH) is much longer and contains the paths to the desired executables.
I found some questions treating on the same subject but none could help me with this.
Any help appreciated!
PATH is created by whatever shell you're running, but ProcessBuilder does notrun within a shell and therefore there isn't a PATH to attach to, to resolve your program names. You can provide an environment to ProcessBuilder, but don't believe it's going to let you find your program that's in the PATH. In a project of mine I had to provide a fully-qualified path.]
[NOTE: Mileage may vary, I seem to remember having somewhat different results between Windows and *nix, and between different *xix.]

java.exe is not recognized as an internal or external command

I have already read some posts but I cant solve my problem yet.
I am working on a remote desktop and windows server 2008. In the shared disk E: I put some batch file. This batch files call a new batch file from server which runs java script. And now I am taking the this message.
java.exe is not recognized as an internal or external command, operable program or batch file.
I try to set the environment like :
First setup the JRE7 to disk E
Second create new user variable which name is JAVA_HOME and which path is my JRE path E:\Tool\BatFiles
But I am still taking this error. Where should I do wrong ?
Setting JAVA_HOME is a good step, and with it you should be able to run Java as follows
%JAVA_HOME%/java myProgram arg0
If you don't want to include %JAVA_HOME in your command, you will have to include it in your PATH. Windows checks it's PATH for bin scripts every time a command is called. A typical Java installation does this for you.
You can edit your PATH to include ;%JAVA_HOME% at the end. Restart your command prompt for changes to take effect.
Edit 1
Be careful when editting your PATH however! Windows depends on it to function in many aspects. You can expect explorer to stop working. Make sure before altering your PATH variable, that you back it up somewhere. Just in case.

How do I set the Environment variables for Jython?

I have set the variables JYTHON_HOME to the directory where I have installed Jython and JYTHON_PATH to the bin folder, but I still get the following error when I try to run jython:
'jython' is not recognized as an internal or external command,
operable program or batch file.
Why do I get this error? The Java installation has no issues.
I am Windows user & I have installed Jython in C:\jython2.7.0.
What I had before?
I had neither set the JYTHON_HOME environment variable nor added %JYTHON_HOME%\bin to PATH environment variable. I also got the same error as shown in the question.
How I fixed?
I created new environment variable named JYTHON_HOME with value C:\jython2.7.0.
You've to use your own Jython's installation folder.
Then I added %JYTHON_HOME%\bin to PATH environment variable as the below 2 image shows.
Create new PATH environment variable if it is not already there (This is rare case).
Open new Terminal and type jython, it will work. Now you can try executing simple Python statements as the below image shows.
Do not use the already opened Terminal.
That's it.
You still need to add the path to the executable jython.bat to your PATH environment variable. Here as an example I'm providing my ini-jython.bat, which I use before executing my jython project (in this case it's a Django on Jython project, you can safely ignore the Django stuff, or adapt it to your needs):
set JYTHON_HOME=c:\tools\jython2.5.2
set PATH=%JYTHON_HOME%\bin;%PATH%
set CLASSPATH=dep1;dep1/lib/*;_lib/*
set JYTHONPATH=.;..\django-debug-toolbar;..\django-common
set DJANGO_SETTINGS_MODULE=site_projname.settings
set PYTHONPATH=%JYTHONPATH%
set manage=jython c:\tools\jython2.5.2\bin\django-admin.py
set makemessages=django-admin makemessages --extension html,py
set compilemessages=django-admin compilemessages

'javac' cannot be found problem

I have a Java application hosted on a remote tomcat instance that executes a bat file which contains the following line
javac filename.java
I receive the following error :-
'javac' is not recognized as an
internal or external command, operable
program or batch file.
I have set the path in the environmental variables. I tried running the same bat file on the machine, it works(which means there is nothing wrong with the path). But running it through the application gives the error. What might be the problem?
Setting the correct path in your environment does not fix the path in the environment of the running tomcat process. If you changed the path in the system settings, a tomcat restart (or system reboot) probably solves your problem.
Once you add %JAVA_HOME%\bin to the PATH var on the remote machine (assuming you have %JAVA_HOME% set there), you will need to run up a new cmd window for the new PATH to be available.
You should set the classpath for the user who is executing tomcat, not only for your login user.
If you have the JRE installed, and not the JDK, you'd be able to run Tomcat but there wouldn't be a javac.exe. Go to JAVA_HOME/bin and see if there's a javac.exe. If not, you have the JRE installed, and you'll have to go get the JDK.
Just curious - why is your Tomcat app calling javac.exe? Are you creating classes on the fly? If yes, why would you not be generating byte code using ASM instead?

Categories

Resources