How to run jar files in Mac using JRE? - java

Mac OSX 10.11.14 (El Capatin) does not ship with Java, either the complete development kit (JDK) or the run-time environment (JRE). My need was to just run a .jar file and not for complete Java development. So I downloaded the JRE from here, which is a much smaller file compared to JDK (quite obviously).
This SO answer says that JRE is enough to run jar files.
After installation of JRE I couldn't locate the directory where installation happened or run java command to execute files on my mac. How do I run jar files now?

To run java application you can either use
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
or (as you found)
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
In any case, if you need to run java often, you should set JAVA_HOME in either your ~/.bash_profile or ~/.profile and amend the PATH to include the bin directory.

After JRE installation, the correct path is:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin
But now, how do I run the java command? It seems like the java file located in the directory above is not an executable.

Related

What makes Oracle SOA Suite 12 JAR unable to recognize the JAVA_HOME?

I am trying to install Oracle SOA Suite 12 on Windows 10. I set the JAVA_HOME correctly (able to echo it), and then trying to run the JAR. It gives me the following message:
This installer must be executed using a Java Development Kit (JDK)
but C:\Program Files\Java\jre1.8.0_161 is not a valid JDK Java Home.
It seems to look for the JRE folder and by default neglecting the JAVA_HOME environment variable. I did a workaround by navigating to the JDK folder, and then running the java.exe inside the JDK folder (java.exe -jar /path/to/soasuite). It works well. I just want to know what might be the reason.
I advise you to set the properties as follow. Adapt correctly to your path in the JAVA_HOME property, and the others will follow.
JAVA_HOME := C:\java\jdk1.8.0_151
JDK_HOME := %JAVA_HOME%
JRE_HOME := %JAVA_HOME%\jre
CLASSPATH := .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
PATH := %JAVA_HOME%\bin;%PATH%
EDIT:
I did a workaround by navigating to the JDK folder, and then running
the java.exe inside the JDK folder (java.exe -jar /path/to/soasuite).
It works well. I just want to know what might be the reason.
This means that you are missing the change in the PATH environment.
I was not able to utilize the path variables described - did not want to restart the machine durng and install of oracle software. I was able to successfully complete the install of weblogic oracle fusion by doing the following.
RUN JAR files using command prompt due to having issues running the java installed setups for oracle12c, weblogic ,etc.
RUN command prompt as adminsitrator:
1. CHANGE DIRECTORY IN COMMAND PROMPT TO:
C:\Program Files\Java\jdk1.8.0_181\bin
RUN the command like this - pointing to the proper JAR file.
java -jar c:\oracleformssoftware\fmw_12.2.1.3.0_infrastructure.jar
This definately worked for me but please note I did finally setup the path variables instructions noted here.

Installing Spark on Windows not working

I am trying to install Apache Spark on my Windows 10 computer. My first step to install Spark was to download Java from here it was then downloaded through this path: C:\Program Files (x86)\Java the one folder that was downloaded during this installation was: \jre1.8.0_151
Next I installed the JDK from here and downloaded the windows x86 version. I used the same path as above in the Java folder to download it. After it was done I had two folders inside the Java folder: jdk1.8.0_151 and jre1.8.0_151
Afterwards, I set the JAVA_HOME variable to point to C:\PROGRA~1(x86)\Java\jdk1.8.0_151 and in Path I added %JAVA_HOME% I then installed Scala from here and downloaded the Scala binaries for Windows. The environment path was added in path as: C:\PROGRA~1(x86)\scala\bin
Next I installed Spark from here and installed spark-2.2.1-bin-hadoop2.7.tgz Afterwards, I placed this folder here D:\spark-2.2.1-bin-hadoop2.7I then added the environment variable as SPARK_HOME with the path: D:\spark-2.2.1-bin-hadoop2.7\bin and I then updated path to %SPARK_HOME%\bin
Finally I tried to see if everything was installed. I typed java -version and the correct java was installed. I then typed scala and scala was open for me to type in expressions and such. I then typed in spark-shell but I got this error:
'spark-shell' is not recognized as an internal or external command,
operable program or batch file.
What am I doing wrong that is not making spark open? Please note: I am using cmd for everything.
It looks like you set your %SPARK_HOME% to a wrong place and thus when "I then updated path to %SPARK_HOME%\bin" it resulted in adding D:\spark-2.2.1-bin-hadoop2.7\bin\bin with double \bin which is obviously wrong. %SPARK_HOME% should be without \bin.
Generally you can test your environment variables by calling echo %PATH% in the command line or SET to show all of them

Finding JDK inside java installation folder on a linux machine

I have been told that in a Linux machine java along with jdk has been installed in /usr/java path.
But when I go to /usr/java/ i could so many files along with folder named bin,JRE. I want to know where is jdk installed here? Is bin folder itself is jdk?
My ls output for openjdk7 looks like this:
ASSEMBLY_EXCEPTION docs jre man THIRD_PARTY_README
bin include lib src.zip
The jre folder contains the JRE, the other files are part of the JDK, and not necessary for running Java applications which need only a JRE (e.g. the javac compiler in bin).
Open terminal and type " Which java " this will return JDK installation path
I guess you just installed the JDK under /usr/java. Try run ls /usr/java/bin, if java and javac is in /usr/java/bin, we can conclude that the /usr/java folder IS the JDK folder itself.

javac cannot be run, and furthermore does not seem installed

I have a problem involving setting up Java.
I have installed the JRE, added its path to PATH, and set JAVA_HOME and CLASSPATH. Now, java and javacpl work fine, but running javac generates a command-not-found error. Furthermore, javac.exe does not even seem to exist in the JRE's bin folder.
How do I run javac?
The JRE is merely the Java Runtime Environment, which includes only the infrastructure needed to run Java programs that are already compiled.
To compile Java source code using javac, you need the Java Development Kit (JDK).
On Oracle's Java download page, choose the package labelled "JDK".
In order to use javac in cmd , JDK must be installed in your system...
javac will not work if you are pointing "bin" folder inside JRE (C:\Program Files\Java**jre7**\bin)
Please check for javac.exe inside your bin folder(C:\Program Files\Java**jdk1.7.0_45**\bin)
javac.exe must be inside JDK(C:\Program Files\Java\jdk1.7.0_45\bin) not inside JRE (C:\Program Files (x86)\Java\jre7\bin) "JRE doesn't come with a compiler. It is simply a java runtime environment. What you need is the developmental kit." in order to use compiler javac
For javac path(Points to remember while setting system env variable)
path = C:\Program Files (x86)\Java\jre7\bin this is wrong
path = C:\Program Files\Java\jdk1.7.0_45\bin this is correct
Make sure "javac.exe" must be inside your "C:\Program Files\Java\jdk1.7.0_45\bin"
Dont confuse with JRE and JDK both are totally different
if you dont have JDK pls download from this link http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
reference thread for JDK VS JRE What is the difference between JDK and JRE?
Procedure:-
Install JDK
open cmd prompt
type "cd C:\Program Files\Java\jdk1.7.0_45\bin " press enter(path may change based on jdk version and 32bit and 64bit os version)
type "javac" press enter
its done
Now go and change your system environment variable
path = C:\Program Files\Java\jdk1.7.0_45\bin
this will set the path permanently
The JRE doesn't have javac - you need to download the JDK (Java Development Kit).
First, you need to install the jdk, then add the path of bin folder of jdk in the path vaiable.
you can refer to this link

Why does java -version return an old version?

OS: Windows XP
I am using yuicompressor-2.4.2 to compress some CSS before uploading to my server.
But when I run it, the following exception appears:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/yahoo/platform/yui/compressor/Bootstrap (Unsupported major.minor version 48.0)
So I think it's because of the JRE.
I typed in the command:
cmd: java -version
And it says:
java version "1.3.1_01"
But it should say 1.6.0_16, since I have installed the latest version.
What should I do to make Java use the latest version instead of the old one?
Set the environment variable JAVA_HOME pointing to the directory where you have jdk 1.6.0
set JAVA_HOME=your_path_to_jdk1.6
set PATH=%JAVA_HOME%/bin;.;..;%PATH%
That's from a command window. Also you can do it from "My PC > Properties > Advanced > Environment variables"
Go to the system32 directory C:\Windows\System32 and delete following 3 files
java.exe
javaw.exe
javaws.exe
Now create a JAVA_HOME environment variable with value={root path of your jdk installation} and add the path till bin folder of your jdk in the PATH environment variable.
Open a fresh command prompt and run java -version to confirm the change
If you are using windows 7/10 go to command prompt and type
where java
Delete all the symbolic link shows below other than your actual installation directory.
Even if correctly added all the environment variables still sometime you can get wrong versions especially when you have multiple version installed in your system and want to switch between them.
On Windows, the JRE installs a java executable in the Windows directory, which should be the first java in your path. This is just a wrapper that looks in the Windows Registry to find the Java home directory (should be "%SystemDrive%\Program Files\Java\jre6" for Java 6) and runs using the libraries there.
Run %SystemRoot%\system32\java -version and see what you get. If that is Java 6, you have entries in your path before %SystemRoot%\system32 (which really should be first). Either fix your %PATH% variable, or you'll have to be explicit whenever you want to run this version of Java.
If running that instance of java doesn't report Java 6, its not installed (correctly). Uninstall and try installing again.
If you are having trouble because of the PATH, it is because you or some software you installed monkeyed with it; I recommend using the default which is to have system32 first. Everything works fine if the defaults are used.
Also, %JAVA_HOME% is not used by the JRE itself at all. Some common Java applications like tomcat and ant honor the %JAVA_HOME% setting, so perhaps yuicompressor does too. But this is a de facto convention, not a standard.
after where java in Command prompt
for example
where java
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-11.0.10\bin\java.exe
delete C:\Program Files\Common Files\Oracle folder
then close all terminals and write java -version in the terminal. it will show the right version
worked for me
You should modify your PATH environment variable:
My PC > Right click > properties > Advanced > Environment variables
And modify "Path"
Append at the end the path to your 1.6 installation:
;C:\jdk1.6.xxx\bin
and remove the previous one if present.
Add %JAVA_HOME%/bin to your PATH environment variable where JAVA_HOME is set to your JRE6u16 directory
I had the same problem. In System Properties > Environment Variables > System Variables > PATH make sure there is no other path associated with Java. To make sure, type in and check Java paths.
where java
Re-open Command Prompt and type java -version again. I hope this helps.
first by the following command, you should be aware of .exe file which runs when you type java in the command prompt
where java
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-11.0.10\bin\java.exe
as you see above , cmd first reads java from
C:\Program Files\Common Files\Oracle\Java\javapath
so go to the path above and remove java files .
then it should work fine
You should check your PATH environment variable. It is possible that some application you have installed has put its version of the jre in front of yours in the path.
It looks like the older Java version is still on the system PATH environment variable (where the OS looks for commands) or JAVA_HOME (where yuicompressor may look for the java executable)
How those variables are changed depends on your operating system.

Categories