As you can see, it works when running as non sudo. I however need to run it as sudo.
Asked
Active
Viewed 153 times
2 Answers
0
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.

prsutar
- 429
- 2
- 4
- 17
-
Added the code, displays the following `java.library.path=/home/karl/workspace/sslarp/lib/:/usr...`, which is correct. Which directory shall I add to the `CLASSPATH`? – basickarl Nov 30 '14 at 14:19
-
do one thing add this line System.out.println(props.getProperty("java.library.path")); it will display full classpath, search for class containing method getmacip in given classpath – prsutar Nov 30 '14 at 14:27
-
check if java home is added in above. – prsutar Nov 30 '14 at 14:27
-
Output is as following `/home/karl/workspace/sslarp/lib:/home/karl/workspace/sslarp/lib` – basickarl Nov 30 '14 at 14:28
-
i think your java home is not in classpath, to set it from eclipse refer following link, http://stackoverflow.com/questions/957700/how-to-set-the-java-library-path-from-eclipse – prsutar Nov 30 '14 at 14:30
-
Ah, that is via Eclipse, I am forced to go via the terminal in this case for the sudo. :/ – basickarl Nov 30 '14 at 14:34
-
Karl, you can also do via terminal, like java -Djava.library.path=blahblahblah... – prsutar Nov 30 '14 at 14:36
-
Doh! Sorry I misunderstood the link, and it did indeed work with sudo via the -Djava. Why is this, any explanation? P.S. update your answer and I'll happily accept! (Don't remove the code though, it was helpful) – basickarl Nov 30 '14 at 14:40
0
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).

RealSkeptic
- 33,993
- 7
- 53
- 79