How do I set the Environment variables for Jython? - java

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

Related

I want to set an environment variable to my java application while bootstrapping such that the jars in classpath can read it

I have to set LD_LIBRARY_PATH such that one of the jar in my classpath uses that to execute some native java files.
I have tried setting up the environment file to my server while bootstrapping, but
System.getenv(LD_LIBRARY_PATH) is given as null.
Library path in use by Java is shown by System.getProperty("java.library.path"). Just print the value in your app when you run it.
java ... your.App
Note the value and edit LD_LIBRARY_PATH before running a second time:
export LD_LIBRARY_PATH=/blahblah
# or export LD_LIBRARY_PATH=/blahblah:$LD_LIBRARY_PATH
java ... your.App
You should see the changed "java.library.path" now prefixed with /blahblah:.

Using Java code to get env variable returns null in MacOS Catalina [duplicate]

What is the proper (2021 way) of creating a permanent environment variable on a Mac (macOS Big Sur) and then use it within a Java project.
There are many very old posts regarding this topic. None of them seem to work properly nowadays.
How to add a permanent environment value (through terminal)?
And how can I use it in a Java code?
I'm also not sure how I was able to add my testvar=testvalue to the list, because I tried so many files (although it seems none of them worked), by adding export testvar=testvalue to the following files:
/etc/paths
~/.bashrc
~/.bash_profile
~/.profile
/etc/profile
Also after inserting it into each file I used source {file}.
So at this point I have no idea which is the proper way to create and have it permanently, and being able to use it in my Java code.
So far, I can print the variables into the terminal like this:
printenv
My variables are getting listed, example:
testvar=testvalue
In my Java code, I get null when using:
System.getenv("testvar")
However using an other variable names that were not created by me, but the macOS system (eg. "USER") prints the value as expected.
macOS Big Sur uses zsh as the default login shell and interactive shell.
If you’re using a Bash profile, such as to set environment variables, aliases, or path variables, you should switch to using a zsh equivalent.
For example:
.zprofile is equivalent to .bash_profile and runs at login, including over SSH
.zshrc is equivalent to .bashrc and runs for each new Terminal session
You can create .zprofile and enter the enter the environment variables there.
Reference
you can edit zprofile using the following command
sudo nano ~/.zprofile
and add your PATH variable.
# Setting PATH for Python 3.9
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH
to add multiple values to the PATH variable, just add more PATH keys. For example, this is how I added multiple path variables in my M1 mac Monterey
# Setting PATH for Python 3.9
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
PATH="/Users/<name>/.local/bin"
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PATH
This depends on the shell which you are using. For Big Sur, the standard shell is zsh, which might explain why .bashrc and other bash-related configuration files did not work. If you want to set environment variables for your account in zsh, try to create a ~/.zshenv file and put the variable declarations there.
See also: http://zsh.sourceforge.net/Doc/Release/Files.html#Files

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.

Java settings, classpath and environment variables

I'm not sure if it is best practice but I add MySQL-connector jar to the extensions directory of my Java install directory to I can easily connect to MySQL databases.
I also set environment variables to point to various directories so that I can develop on different machines and only define environment variables locally and code doesn't have to be modified for file paths.
In either case of the above I find that unless I reboot my computer java does not recogise either. What happens during a reboot to Java? Is some config file updates by a java process? Can you update this without having to reboot?
To test this I have created a new environment variable on both Mac (adding to .MacOS/environment.plist), Linux (Ubuntu 12.04) and windows 7 (via control panel). I then used System.getenv("TestVar"); which returns null. Running set from the command line shows it exists though. After a reboot System.getenv("TestVar"); returns the expected value.
Ultimately your goal is to include jar files in CLASSPATH . its up to you how include jars in classpath but this is not good practice to put jars inside extensions directory . While running your program modify CLASSPATH value .
java -cp jar1:jar2:jar3:dir1:. HelloWorld
java -classpathjar1:jar2:jar3:dir1:. HelloWorld
As far as setting environment variables goes the on Ubuntu a log out is required
https://superuser.com/questions/339617/how-to-reload-etc-environment-without-rebooting

'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