Force java path mac - java

Before you answer "export JAVA_HOME=whatever >> ~/.bash_profile", just know it won't work. I even restarted my terminal and typed echo $JAVA_HOME, and got the right path.
How do you force (and I mean FORCE, not tell-java-it-exists) a custom path for the java home directory. My java 7 in installed in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java. Java doesn't recognize the java path. When I type java -version, it says 1.7.10_60. But, when I type java -version:1.7.10, it says it doesn't exist. When I launch my binary, it says Java 7 is required. It is a UNIX executable, and won't launch with the java command (with or without -jar).

You need to install the actual JRE (that path looks like just a plugin installation for applets). You can get it here

Related

Where can I find my java installation when where java gives nothing?

It's definitely installed, I can run Minecraft. But I'm trying to run a .jar file and Windows 11 is asking "How do you want to open the file?" And java compiler doesn't show up. btw I've treid where java, it said java didn't exist on the computer
UPDATE: I solved the problem but not the issue, there were some mods that were incompatible with eachother
You could try to find it out via printing your PATH.
On Windows: Open the command line via
Start -> CMD
Paste in
echo %PATH%
There you should be able to find the java path. Otherwise try to search for JRE.
By the way it is not always 100% sure that you have the java runtime and java compiler installed.
JRE = Java Runtime Environment for executing .jar
JDK = Java Development Kit for compiling java files and creating .jar files

JDK java executable vs JRE executable

I installed the Oracle JDK to /usr/jdk/jdk1.8.0_25 and set that directory to JAVA_HOME.
JAVA_HOME/bin contains the java executable and JAVA_HOME/jre/bin contains another java executable.
The guide I followed said to add JAVA_HOME/bin and JAVA_HOME/jre/bin to the PATH but which is the correct executable to use and which will be used if I call java from the command line?
Here is a simplified overview of the differences between JDK and JRE
JRE means JavaRuntimeEnvironment : it contains only binaries for running java program
JDK means JavaDevelopmentKit : it contains binaries for running java program + binaries to compile java source code (and produce a java program).
A JDK always contains a JRE inside (under directory <JDK_HOME>/jre)
The major difference between JRE and JDK is the javac program. (javac means java compiler)
(you will also find some other programs under the <JDK_HOME>/bin that aren't present under <JDK_HOME>/jre/bin : all of them may be useful to do java development - but in most case - useless to run a java program.
All programs that are in both locations (i.e. <JDK_HOME>/bin and <JDK_HOME>/jre/bin) are the same, so it is not very important to make a distinction.
To answer precisely to your question : the java instance that will run when you execute a command line starting with java is the first instance of java found in your PATH system variable... just like any other program.
Whatever is earlier in the path for java - JAVA_HOME/bin or JAVA_HOME/jre/bin.
If you take a look at the folder structure where jdk / jre is installed you would see that in the jdk/bin folder there are quite a collection of binaries such as java, javac, javap etc. The JRE would include java but not javac, javap etc. I am assuming this is linux and you downloaded the compressed archive and extracted that.
If you are really curious, you can write this to the command line:
where java
This will give the exact location of the executable. On my PC this gives me
C:\ProgramData\Oracle\Java\javapath\java.exe
which is a soft link for the system default runtime java.exe (in my case it is C:\Program files\Java\jre 1.8.0_25\bin\java.exe)

Run a Java program with java.exe in the same directory without installing

I know there are lots of posts similar to this, but all of their answers require creating an .exe file. I want to know how to run a program in a folder without installing java.
I don't want to install Java 8 as it breaks some of my programs. I want to run a java program in a folder using a start.bat file that points to the java.exe file in the same directory. Like this:
"java.exe" -jar program.jar
The error is like this:
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.7', but '1.8' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
Since the command window is opened in the same directory, "java.exe" should point to the java runtime.
Can I maybe copy java.dll to the directory to make it work? How can I do this without installing java 8? Could I use java ME?
Why don't you create a .bat file that declares a new JAVA_HOME and appends to the PATH just for this DOS/batch session, then you can point to a place where you have the required JRE (however, you kind of have to install it... it's a Windows thing).
I understand you are reluctant to install the JDK/JRE 8 on your Windows because of this: "I don't want to install Java 8 as it breaks some of my programs". But trust me, you can always change the JRE version on the Java Control Panel (windows >> control panel >> Java) and change the JAVA_HOME & PATH environment variables, you might have problems with your browser's plugins though, the Java install will affect them as well.. I guess, in that, case you can either try to skip this part of the install process or.. install JDK 7 again afterwards?
IF you just want to run this program, you can also install VirtualBox and create a VM with windows and install the JDK8 there, avoiding any problems in your OS.

Installing Java on Windows 8

I'm in a Java I class and I have a new-ish laptop with Windows 8 on it. I've installed Java and changed the environment variables, created a Path, etc. When I enter java or javac in the cmd, it comes back with information. But when I enter "java-version" (as I'm instructed to do in the class to test if Java is working) it says, "'java-version' is not recognized as an internal or external command, operable program or batch file".
I've even attempted a HelloWorld program in spite of this, and as you can imagine, I got the same message. I'm not even able to change the directory.
Is there some special way to install this on Windows 8 or what?
You need to type java -version instead of java-version
First of all ensure you have typed Java -version space between Java and -version
No there's not special way to install Java on windows 8 machine, Just ensure that you have added ..\Java\jdk_(version)\bin and ..\Java\jre\bin in environmental variables.
Steps to be followed :
Right click on my computer go to properties
Then go to Advanced
system properties then click on environment variables
and add both path in Path variable under System Variables add semicolon between two paths
after all process don't forget to restart your PC
There is no special way to install java on windows 8. You can install java in normal way what you did in windows 7 or vista or windows xp and configure. Then run java -version, It will give your java version.

Even if $JRE_HOME is not set java -version is displaying properly

I used sudo apt-get open-jdk7 to install Java on my Ubuntu OS.
When I open a terminal and type echo $JRE_HOME it displays nothing. But then I do java -version it shows me correct version of OpenJDK. Also when I simply type java it works.
Not sure how Ubuntu set the path of java.
Similarly javac works but I don't see anything when I say echo $JAVA_HOME.
My path does not show java directory path in it.
Where is Ubuntu setting the java path? Why does Ubuntu not set JAVA_HOME and JRE_HOME during installation of OpenJDK?
It's a common misconception that Java somehow requires JAVA_HOME, JRE_HOME or similar environment variables to be set to work.
In fact the java and javac (and related) executables don't really care about those variables. They only need to be on the PATH (or can be executed via a full path if not on PATH) and will find their related install by looking "near itself" (i.e. the executable are usually installed in a known location relative to the JVM files).
There are a few third party scripts that use JAVA_HOME and/or JRE_HOME to find a Java installation (Apache Tomcat is a well-known example for this), but the Java executables themselves don't need those variables.
As to how Ubuntu finds the executables is easy to answer: use which java and which javac to find out which executables are executed when you type those commands. On Debian-based systems they are usually a series of symlinks through the alternatives systems that point to the actual executables.
"Where is ubuntu setting java path?", ubuntu does not set the open-jdk-java-path automatically.
try
find / -name "java"
to locate the javac. And write
export JRE_HOME="xxx"
(where xxx is the base of the open-jdk-jre.)
BTW: You got nothing than trouble with open-jdk. You better use the sun-jdk.
As many Linux distros, Ubuntu has /etc/alternatives in its paths. If you type:
which java
Then you'll get
/etc/alternatives/java
If you type:
ls -l /etc/alternatives/java
Then you'll get
/etc/alternatives/java -> /usr/lib/jvm/<your java version>
A few mor ls -l -s can help you to get the full picture.

Categories