Append java.library.path in command line - java

-Djava.library.path="path to a dll"
This replace the environment path variable in the current session. I want to append this path to the already existing path.
Kindly let me know how to do it. I'm calling a jar from command prompt using
java -Djava.library.path="path to a dll" -jar myjar.jar

On Windows: Add the path to the library to the PATH environment variable.
On Linux: Add the path to the library to the LD_LIBRARY_PATH environment variable.
On Mac: Add the path to the library to the DYLD_LIBRARY_PATH environment variable.
java.library.path is initilized with the values of the variables above on its corresponding platform.
You can test if the value is what you expect by calling java -XshowSettings:properties

You can try -Djava.library.path="%PATH%;path to a dll" or if it does't work
you need to get existing PATH variable value and add you path to it.

Related

Path variable issue in cmd commands and java commands

When I set path C:\Windows\System32, the ipconfig command works, but javac and java -version commands don't work.
While, when I set path variable to C:\Program Files\Java\jdk-14.0.1\bin they work, but ipconfig command stops working.
How can I solve it in order to make work both the commands?
Welcome to SO.
You can extend your PATH variable with additional directories instead of replacing it.
See also: Adding a directory to the PATH environment variable in Windows
Add both the folders to path variable seperated by ';'
eg
PATH1;PATH2

I have installed Java 8, set environment variable and JAVA_HOME, but my system tries to find java.exe in wrong path, how do I correct it?

I have installed Java 8 and set my JAVA_HOME and JRE_HOME paths and added %JAVA_HOME% to the start of the path variable.
When I try to run simple java program I get error as
"The system cannot find the file C:\spl\java\bin\bin\java.exe".
The above path contains extra bin.
Where as environment variable and JAVA_HOME has C:\spl\java\bin\ this path.
I cannot understand from where this extra bin directory is coming.
Please help.
From where does system is taking C:\spl\java\bin\bin\ this path?
Your JAVA_HOME should point to the ...\Java\jdk1.8.. directory.
In Your path you should have %JAVA_HOME%\bin.
Some applications refer to JAVA_HOME and add \bin on their own, so you must not add \bin to your JAVA_HOME. Otherwise, you'll receive correct error saying, that C:\spl\java\bin\bin\ doesn't contain Java.exe
Solution:
Remove \bin from your JAVA_HOME
It is quite clear from your example: the system is taking %JAVA_HOME% as the "home" of your java installation, not its bin directory. So when you try to start java.exe, it looks in %JAVA_HOME%\bin. Just remove the bin part of your JAVA_HOME.

Java: System cannot find the file C:\ ... java.exe

I have installed Java 8 and set my JAVA_HOME and JRE_HOME paths and added %JAVA_HOME% to the start of the path variable.
I created a helloworld.java application and am able to compile it using:
javac helloworld.java
However, when I try to run:
java helloworld
I get the error:
The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe
How can I solve this?
1.Just go to C:\ProgramData\Oracle\Java\javapath\
2.You will find there shortcuts for java.exe,javaw.exe,javaws.exe which are pointing to a location where they actually are not existing now
3.Go to the jre location where you have installed java like C:\Program Files\Java\jre6\bin
You will find java.exe,javaw.exe,javaws.exe
Create shortcuts for these files and replace with the ones which are present in C:\ProgramData\Oracle\Java\javapath.
It works
Just set %JAVA_HOME%/bin to your path variable.
If you are blocked from modifying system variables from command line, but are able to open up an elevated command prompt, then run a command like this:
setx \M JAVA_HOME "C:\Program Files\Java\jdk1.8.0_25"
But of course, change the directory to point to your installed version of java. Note that the JAVA_HOME path does not point into the bin directory, it stops one level above bin.
I was able to solve this issue. To do so I used the advice from this answer:
Java SE Development Kit 8u25 on a 64-bit Windows 8
Set the following user environment variables (== environment variables of type user variables)
•JAVA_HOME : C:\Program Files\Java\jdk1.8.0_25
•JDK_HOME : %JAVA_HOME%
•JRE_HOME : %JAVA_HOME%\jre
•CLASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
•PATH : your-unique-entries;%JAVA_HOME%\bin
(make sure that the longish your-unique-entries does not contain any other references to another Java installation folder.)

JAVA_HOME set but not taking effect

As depicted in above image java home is set and is being echoed but when i check for version it gives me latest version.
Already restarted the command prompt after setting env variable.
OS is Windows 7
Update:
Following is the Path.
..ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;;%JAVA_HOME%/bin;
I had the same trouble and I solved it with the following steps:
You need the correct environment variables.
To be exactly correct, you only need to set the Path variable.
You need to find where you add %JAVA_HOME%\bin to the path.
Put it at first place in the Path variable:
%JAVA_HOME%\bin;...
where ... represents all other values of Path.
I assume that JAVA_HOME is defined as a variable and had the correct value.
After this reopen console and check:
java -version
JAVA_HOME is environment variable that various application reads in their launcher script
when you invoke java it looks up for all paths specified in your env variable named PATH and wherever the first match is it gets picked up
so if you like command prompt to refer to jdk 6's Java append the path to PATH
You need to add the path to jJAVA_HOME%/bin directory in the path variable too. java command is located in %JAVA_HOME%/bin
Check your PATH environment variable also. Your system is referring to latest Java installation through PATH variable.
I think in your path variable you have hardcoded the path to bin folder. it should always be %JAVA_HOME%/bin.
So that it can pick path from JAVA_HOME variable and you don't need to change both the variables every time.

Javac Command Not Working

My javac command is not working.
"javac is not recognized as an internal or external command, operable program or batch file."
-java version WORKS
I've tried setting classpath successfully in command prompt. SET CLASSPATH "C:\Program Files\Java\jdk1.7.0_09\bin";
Ive adding it in environment variables. ;C:\Program Files\Java\jdk1.7.0_09\bin ;C:\Program Files\Java\jre7\bin
Ive checked the bin folder java.exe is there aswell as javac.exe.
^ Tried all of these still doesn't work. I've also restarted command prompt still does not not work.
Why is not working?
You're using the correct path apparently, but you should assign it to the PATH variable, not to the CLASSPATH variable.
You're trying to set the access path to the executable files, not to the class files.
Just do this
In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK,
e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
Just set JAVA_HOME to
C:\Program Files\Java\jdk1.7.0_09
After adding the path to the jre7\bin-Folder to the PATH-Variable, you need to restart your Computer in most cases.
Did you tried to create a JAVA_HOME variable? The value should be the path of the java without the bin.
Also, try to open Eclipse.
If nothing helps, the last thing that you can do is install netbeans, it will configurate everything.

Categories

Resources