As you can see, it works when running as non sudo. I however need to run it as sudo.
I have faced this error this comes when there is classpath issue. Set classpath from command prompt, do via terminal, like java -Djava.library.path=blahblahblah... liked helping you.
Try either using sudo -E (which will pass your environment variables to the sudo environment), or pass the specific environment variables that you wish:
sudo LD_LIBRARY_PATH="$LD_LIBRARY_PATH" CLASSPATH="$CLASSPATH" java ...
(You may not need to pass the CLASSPATH, you can try with or without it).
Related
I'm trying to deploy an API do AWS EC2.
And this API has environment variables inside application.properties, such as $DB_HOST, $DB_USER and $DB_PASS, and then I set them at
vim .bashrc
source .bashrc
All the process occurs alright for the deployment, but when I run
sudo mvn package
It doesn't recognize the environment variables setted from the OS (linux) and build fail.
I can't really find any similar solution here.
Also tried putting them inside the /˜profile with
nano /˜profile
source /˜profile
Anyone has any ideas? :)
When you use sudo, it doesn't use your environment variables but those of the root user (or in case you use sudo -u <user>, that user).
I suggest not using sudo without specifying a user. That means that the code is running as root, which is a big security risk. I'd create a new user dedicated for your application. You can configure that user's environment variables as well.
I am trying to update RJava to reflect the latest version of Java 1.8 on my mac. I think I found the right information in doing so but the issue arises when I use 'Terminal' to run some code. I have to run:
sudo R CMD javareconf -n
but I receive an error of:
sudo: R: command not found
I found some information online and I found out I need to change the path in Terminal. I found out that the path where R is '/usr/bin/R'. When I changed the path using the command:
export PATH=/usr/bin/R:$PATH
and then tried to run the code again; I got no where and I am out of luck. I don't understand what the code is but I can only assuming what it does. Hopefully I can get some insight on how I can change the path so I can update rJava to the updated Java Version. Thank you for anyone's time.
The PATH setting would be PATH=/usr/bin:$PATH or you even easier
sudo /usr/bin/R CMD javareconf
Note that -n wouldn't do anything so you probably didn't mean that. Also if you don't even have /usr/bin on your PATH, you have probably even bigger issues since you also need to find java in the first place. In cases like that you may have better luck using sudo -i and then using the shell to fix whatever env vars are not setup correctly in your system.
There's an issue when I run the android Runtime.getRuntime().exec method.
I have a native binary file to be run on android and I start it with the java method Runtime.getRuntime().exec. But running this native binary file requires the addition of an environment variable. So I execute this command:
envSetCmd = {"sh", "-c", "export LD_LIBRARY_PATH="+excBinFilepath+":$LD_LIBRARY_PATH"}.
It doesn't work when I check the environment variable with the command:
sh, -c, echo $LD_LIBRARY_PATH.
I think the reason is that when I set the environment variables I start a shell and when I check it with the command "echo" another shell was started. So the environment variables didn't work in the shell I check it.
I think there are two ways to solve this issue. The one is that running two commands in one shell. So I tried to use the command:
{"sh", "-c", "export LD_LIBRARY_PATH="+excBinFilepath+":$LD_LIBRARY_PATH", "-c", "echo $LD_LIBRARY_PATH"}.
Unfortunately it is illegal. The other is that I add the environment variables to the android user startup files. I tried to echo the $PATH, and I see the /system/bin/ and other path was loaded at the startup of android.
So I think there must be a file just like the ~/.bashrc in linux which could set the users' environment.
Any one could give me some clues about the ways I listed above? By the way, I shouldn't root the phone!
try to execute whatever you need to execute with env:
{"env", "LD_LIBRARY_PATH="+excBinFilepath, "yourCmd"}
I am trying to compile and a sample Helloworld.java file.
I have my jdk installed in C:\Program Files\jdk1.7\bin.
And I have my Helloworld.java in C:\Helloworld.java
I am actually a novice in both powershell and java.
I got some examples from web regarding this but many of them advice to run it like this:
java.exe -classpath $Env:CLASSPATH C:\Helloworld.java
But when I give this in powershell I get an error called 'CLASSPATH' is not defined even after adding it in env variables.
And when I try to compile the code with the following syntax:
$javac C:\Helloworld.java I get an error "javac is not recognised as a token".
So, I am literally lost in this topic . Any step by step procedure to run java programs using powershell for dummies like me will be greatly appreciated.
Setup environment variables in your system.
set JAVA_HOME to C:\Program Files\jdk1.7
add to PATH variable the string %JAVA_HOME%\bin
open new cmd session.
navigate your java source folder.
use javac to compile your java files.
UPDATE:
also if you are experiencing difficulities upon launching an executable via PowerShell check this Microsoft TechNet article
The variables you speak of do not exist in PowerShell as you name them.
The correct variable names are
$Env:JAVA_HOME: C:\jdk1.6.0;
$Env:PATH: C:\jdk1.6.0\bin;.;
$Env:CLASSPATH: C:\jdk1.6.0\lib;.;
As they all must be defined in the ENV: PSDrive
To answer it in a much simpler way , its the path problem .
You probably not have set env variables that's it.
This is how you should set it:
JAVA_HOME: C:\jdk1.6.0;
PATH: C:\jdk1.6.0\bin;.;
CLASSPATH: C:\jdk1.6.0\lib;.;
And later if you open a cmd prompt and type java -version , if you are able to see the java installed version then you are good to go.
I have installed oracle jdk in /usr/lib/jvm/ and i have setted up path in etc/environment as
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=$PATH:$JAVA_HOME/bin
But still when i am running javac, I am getting following error. The program 'javac' can be found in the following packages:
* default-jdk
* ecj
* gcj-4.6-jdk
* gcj-4.7-jdk
* openjdk-7-jdk
* openjdk-6-jdk
It means javac is not installed or java path has not setted properly, however i am able to see javac,java,jps and other programs in my /usr/lib/jvm/jdk1.7.0_51. I have searched enough about it but still not able to get solution of this problem.
The file /etc/environment is not a file executed by the shell (like a shell script); you cannot use $SOMETHING references in this file. Variables are not substituted in this file. So,
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=$PATH:$JAVA_HOME/bin
the second line will not work like this. You have to put the exact path in.
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=...:/usr/lib/jvm/jdk1.7.0_51/bin
The javac binary (and probably other java binaries) is/are not in your user's $PATH environment variable. There are several ways you can address this:
Add /usr/lib/jvm/jdk1.7.0_51/bin to your user's $PATH
environment variable. You can do this by adding a line similar to
the following in your user's .bash_profile:
export PATH=${PATH}:/usr/lib/jvm/jdk1.7.0_51/bin
You'll have to restart your terminal session for it to take effect.
Create symbolic links to the java binaries from some directory
that's already part of your path (such as /usr/bin)
sudo ln -s /usr/lib/jvm/jdk1.7.0_51/bin/java /usr/bin/
sudo ln-s /usr/lib/jvm/jdk1.7.0_51/bin/javac /usr/bin/
BTW: There are several other java executables in /usr/lib/jvm/jdk1.7.0_51/bin. see the symlink commands for java and javac above. You should run similar command for any other executables you may want to use.
Use the fully qualified path directly on the command line:
$ /usr/lib/jvm/jdk1.7.0_51/bin/javac
https://help.ubuntu.com/community/Java
have you tried this page? Its where I go when I need Java info. You may not have the one you installed set as default.
Could it be that you did not refresh the shell after change in path variable?
if you echo $PATH are the changes present?