Select sun Java version 7 via command line in linux - java

I have openjdk and the sun version installed, how do i choose the sun version via command line?
I want this for eclipse ptp.

Just explicitly call the right java executable in your command line.
i.e. <path to sun java>\java -jar test.jar

You can do two things if you want to start Eclipse in Sun Java.
Change your PATH variable to have the Sun Java Bin Directory before Open JDK.
export PATH=Path_to_Sun_Java/bin:$PATH
And then start eclipse from the same terminal which will use Sun Java
Edit the eclipse.ini file and specify the -vm option
-vm Path_to_Sun_Java/bin/java

For Eclipse you can start it with the -vm path_to_vm/bin/java option.
If you want to set it for the system, that depends on your OS. Most Linux distributions have a tool that switches system VMs for your (sets PATH and JAVA_HOME accordingly). Maybe setting both in your ˜/.profile on Linux or user environment variable on Windows is already good enough for your purposes?

You can try this script which makes everything for you or follow steps manually with nice explanation.

if for eclipse only but for all eclipse Projects then :
from the dropdown menu window->preferences, then java->installed jre, select your jre, if not there, just browse your system and locate the path to Oracle JRE/JDK
, if for all your OS, here links for linux:
Suse Linux:
http://www.freetechie.com/blog/installing-oracle-sun-java-jrejdk-1-7-update-7-on-opensuse-12-2-x86_64/
Ubuntu:
http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html

Related

Eclipse and Java SDK [duplicate]

I am using Eclipse for developing BlackBerry Applications. I have JDK/JRE 7 currently on my computer, but that makes the BlackBerry plugins crash. Actually is a known issue and the only thing need to be done is run Eclipse with JDK/JRE 6 instead of 7.
I downloaded and installed version 6. However I am pretty sure Eclipse still uses 7. I had the same problem a year ago and I remembered I had to configure some System Variables and it worked, but I can't really find the solution now.
Any idea on this one? Important! I don't want to compile in version 6, which means I just have to choose the Java version through Eclipse. What I need is Eclipse to start with version 6.
Open eclipse config file eclipse.ini in your Eclipse folder.
Add -vm yourPath\Java\jre6\bin\javaw.exe like:
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120522-1813
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-vm
C:\Java\jre6\bin\javaw.exe
...
If the path contains spaces there is no need to escape them, see the Eclipse Wiki for more specs. The -vm option and the path must be on separate lines. The -vm option must come before the -vmargs option. On Linux, the path would typically be /bin/java instead of the Windows path shown above. You must use the Java and Eclipse versions must match (i.e. 32-bit Eclipse runs on 32-bit Java and 64-bit Eclipse runs on 64-bit Java).
Note that option -vm C:\Java\jre6\bin\javaw.exe should be right before -vmargs. Otherwise you'll get 'Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit'
Do this:
1. Go to the folder where eclipse is installed (the one that has the eclipse.exe program in)
2. Open the text file eclipse.ini with notepad or something similar
3. Add the following lines to specify the JVM location using the -vm argument
-vm
c:/jre/bin/javaw.exe
Now start eclipse in the usual way.
Make sure to position the -vm argument before -vmargs, since the latter is passed to the VM on startup it will be too late to set the VM after this.
More info is available on the Eclipse wiki
You could also have changed the system path as per one of the other answers but this would change the JVM being used for the whole system. If you use the eclipse.ini settings it allows everything else to use the latest JVM.
Many hints given already. Anyway I will just provide the recommended way of doing it which might help for future reviews of that question:
Use the eclispe.ini file (folder where the eclipse binary resides)
Add the -vm option with the path of the jre to startup with
i.e Windows
-vm
C:\Java\jdk1.6.0_45\jre\bin\javaw.exe
i.e Linux
-vm
/opt/sun-jdk-1.6.0.02/bin/java
The -vm option must occur after the other Eclipse-specific options (such as -product, --launcher.*, etc), but before the -vmargs option, since everything after -vmargs is passed directly to the JVM.
The -vm option and its value (the path) must be on separate lines.
The value must be the full absolute or relative path to the Java executable, not just to the Java home directory.
see: the eclipse.ini authoring guidelines from eclipse wiki
Since none of the answers worked for me this is my solution:
I downloaded java 6 and i installed it. Then in the program files , inside the folder of java , i copied the folder jre6. I pasted it inside the eclipse folder and renamed it jre.
Thats it! When inside the eclipse installation folder your have a folder named jre , then the java in there is the java that eclipse will run with.
Thank you all for your answers!
These two options worked for me on Windows:
Edit eclipse.ini
-vm
C:/Java/jdk1.7.0_71/jre/bin
-vmargs
...
Copy jre folder to eclipse folder.
So after the copy I have C:\eclipse\jre folder which is a copy of C:\Java\jdk1.7.0_71\jre
If you want to make sure you are running you java apps in Windows 7 with an specific java version:
1 - Check out what which version is running by default. Run cmd to go to the console and type: java -version
C:>java -version
java version "1.6.0_45" Java(TM) SE Runtime Environment (build
1.6.0_45-b06) Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)
2 - Change the default jdk by changing the path. Example here. Make sure you java.exe from your desired jdk is before any other java.exe from any other JDK in the path.
ex. in JDK 1.6 you java.exe should be here C:\java\jdk1.6\bin\java.exe.
Once you have changed the path, open a new console and verify again which jdk version you are running.
3 - Make sure in eclipse.ini param -vm another jre version is not set.
I modified eclipse.ini file as follows (added my local JDK path) and it fixed eclipse loading issue.
-vm
C:\Program Files\Java\jdk1.8.0_251\bin
I too faced same issue while running eclipse with different version then default on the system.
I created a symlink of required jre directory under eclipse directory and then it was all working.
For windows user: symlink is similar to creating shortcut
Hope it helps you too.

Eclipse finds Java from CMD prompt but not from desktop click

I have multiple versions of Java installed on Windows 7 Home Premium 64-bit system. In order to install
Eclipse Java 2018-12
I have had to install the Java 11 JDK from the Oracle website. Despite setting JAVA_HOME and updating PATH in environment variables the only way to install and also run this version of Eclipse was to open a command prompt and
C:>set path=c:\program files\java\jdk11.0.1\bin
and then run Eclipse installer or installed instance.
The problem persists if I reboot my computer.
I want to be able to start eclipse by simply clicking on the desktop icon link.
The error I get when I try to run eclipse from the desktop link is:
Version 1.7.0_79 of the JVM is not suitable for this product. Version 1.8 out greater is required.
My C:\Program Files\Java\
contains folders
jdk1.0.7_79
jdk-11.0.1
jre7
I think I need all of these because I have some programs which I think retire java 7 so I don't think uninstalling java 7 is an option and don't think java 11 would replace it, or should I just get rid of java 7, is that what's causing the problem despite environment variables set correctly?
How can I fix this problem?
Thanks.
Add c:\program files\java\jdk11.0.1\bin to your Windows Environment PATH
The system was running C:\Windows\System32\javaw.exe
I fixed it by adding the Java 11 bin directory at the beginning of the Path environment variable instead of at the end of the string, separated by a semicolon.
First set JAVA_HOME then update path in environmental, refer screenshots attached.

Get Oracle Java 1.8 in windows without installing it

Is it possible to get Java in zip format? I don't want to install it by getting .exe file.
Is there any zip version of Java 1.8 so that I can download it and extract it and start using it in my Windows machine (64-bit processor)?
You can extract the JDK folder from the Installation EXE.
Check this link for the steps. The post was for JDK 1.7 it will work for JDK 1.8 also
Do the following.
Steps
Download JDK from Oracle
Download and Install 7-zip from here
Open installition exe using 7-Zip
Extract the tools.zip
Extract the content of tools.zip to a folder (e.g. c:\jdk).
Open the extracted folder in cmd prompt.
Execute for /r %x in (*.pack) do .\bin\unpack200 -r "%x" "%~dx%~px%~nx.jar" command
Set JAVA_HOME to the jdk (e.g c:\jdk) folder.
Add %JAVA_HOME%/bin to the PATH env variable.
Testing
Run the following command to check the installation, it will print the version of JDK.
c:> javac -version
javac 1.7.0_51
NOTE: Tested with JDK 1.7 and 1.8
Update 1
Edited the answer to add the steps in the answer itself instead of the link to a blog post.
Update 2
For 64-Bit please check unpack-jdk-x64.bat by grabantot
I was looking for a solution to this as well. I'm not sure why the OP wanted to do this. I'm just trying to get a newer version of java for new development while not interfering with an older Java install which a legacy application requires (I'd like to update the legacy app, but it's not an option, now)
I think the hack I am going to try is this:
Install 1.8
Take a copy of the install folder
Uninstall 1.8
Reinstall / Repair 1.7
restore the copy of 1.
I'm sure if I had a better understanding of what the install is doing, this would not be necessary.
I had a spare virtual machine hanging around (if not you could build one or maybe even download one) so I:
installed the Oracle JDK in the guest
copied the jdk folder from the guest to the host
added a JAVA_HOME environment variable.
The operating systems obviously have to be close (not sure how close, I used Windows Server 2008 64 bit guest on a Windows 10 64 bit host and it seemed to work).
Was a quick fix for me as I didn't want a full install and wanted to remove it afterwards.
If you do not have permission to unzip zip file then you cannot install java .
As java does not need installation for running . You just need to give path of java.exe where it is located .
In Windows it is located in C:\Program Files\Java\jdk1.8.0_05\bin
For a solution you can run installer on any machine that you have permission and just copy and paste the folder of java to anywhere in your system (Machine where you have administrative rights problem) . and just set the path as by opening command prompt as set path="C:\Program Files\Java\jdk1.8.0_05\bin"
java will be working as you want
The following worked for me (I had JDK 1.8 installed and needed the 32 bit version as well):
Verify the current version with java -version
Assuming a different version (minor or major is being installed), download the relevant JDK installable from Oracle and run it. In the
first dialog, specify a different folder than the default location
(might work with the default one as well), then select Next. It will
extract the files there in this folder, then it will asl for the
folder where the JRE is to be installed. Simply close the installer,
now you should have just the JDK in the specified folder.
Rerun java -version, it should give you the same version as earlier.
Worst case, if it shows the newer version, go to your system path (Right click My Computer (or This PC) -> Properties -> Advanced
system settings -> Advanced tab -> click on Environment variables
button) and remove the Oracle javapath entry (From the Path variable
in the bottom part of the window). The add the older java version's
bin folder to the path variable in the beginning.
for /r %x in (*.pack) do .\bin\unpack200 -r "%x" "%~dx%~px%~nx.jar"
Is this working for linux shell scripting , I got syntax error for the above.

How to fix error: could not find the required version of the Java(TM) 2 runtime environment in '(null)'

I have researched this and none of the solutions that I have seen have fixed my error.
What is happening is I tried to install Java EE version got the above error and then found out that I must install Java SE first. So I installed Java SE and set the JAVA_HOME variable to C:\Program Files\Java\jdk1.8.0 which is where I installed my JDK. I also put C:\Program Files\Java\jdk1.8.0\bin in my PATH variable. Still not working. I also tried the JAVA_HOME variable with C:\Program Files\Java\jdk1.8.0\bin and that didn't work. I also tried installing without the PATH variable being updated to where I put my JDK.
I'm really getting confused as to why this is happening. I've had Java before and I don't recall having this much trouble installing it.
PS I don't install from the command line I just click the download icon in Firefox and then click the download.
Try running the installer at your commandline and pass the path of the JRE instead of the JDK.
For Example:
java_ee_sdk7-windows.exe -j "C:\Program Files\Java\jre8"
I had the exact same problem and even downloading the version without JDK didn't help!
I simply installed it from the terminal with passing the JRE For Example:
java_ee_sdk7-windows.exe -j "C:\Program Files\Java\jre7"
and it worked like a charm!
I had the same problem but an additional step was required in order to install using the command line. In the command window (on my Windows 10 laptop) I had to use:
cmd /d
to tell the cmd window to ignore registry AutoRun commands before the java installation executable would run. After using cmd /d, and changing to the directory where the .exe file was at, the following worked:
java_ee_sdk-6u4-jdk7-windows-x64.exe -j "%JAVA_HOME%"
Where JAVA_HOME is a system environment variable pointing to an existing JDK installation (C:\Program Files\Java\jdk1.8.0_65).
Uninstall everything, all of it.
Then go to your Program Files folder (and (x86) folder if on a 64bit Windows) and physically remove any Java folders.
Reinstall Java SE and then the EE packages. Sometimes Windows appears to get a bit confused and you need to help it figure out what to do.
If you want to uninstall, go to the glassfish folder and open the command prompt, then type:
uninstall.exe -j <The path to your JRE>
These points may be helpful.
java EE SDK7 contains glassfish v4.0 and it compatible with JDK6 and JDK7.
java EE SDK8 contains glassfish v5.0, it compatible with only JDK7 and JDK8, not JDK 9 or beyond.
So environment variable JAVA_HOME has to point to the root directory of one of the mentioned JDK. and %JAVA_HOME%\bin should be added to environment variable path
Despite having followed all of the above, setup of java EE SDK7 gets error:
could not find the required version of the Java(TM;
as Bakudan and laf8 said,
open cmd using run, with /d /a options as followed.
cmd /d /a
and next run SDK7-setup with -j option like this command
sdk7.exe -j "%JAVA_HOME%"
note that %JAVA_HOME% enclosed BY ""
This was happening to me when I tried to run the Java EE installer. What I did, was to download from Oracle a Java EE version which didn't include the JDK, because it was already installed in my system. Problem solved!
Open regedit.
goto :HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\
set CurrentVersion to desired JDK version.
Check JavaHome and RuntimeLib path's for selected jdk version folder
Check JavaHome and RuntimeLib path's for selected jdk version folder
example: "HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\1.7".
example:
JavaHome=C:\Program Files (x86)\Java\jdk1.7.0_79
RuntimeLib=C:\Program Files (x86)\Java\jdk1.7.0_79\jre\bin\server\jvm.dll
Source: http://tech-read.com/2009/05/19/how-to-solve-error-could-not-find-java-runtime-2-environment-while-opening-an-ide/

Switch from open jdk to Sun jdk

I have jdk1.7.0 directory in /usr/lib/jvm along with other open-jdk versions. I want my Ubuntu 12.04 to treat this jdk(jdk1.7.0) as its primary jdk i.e. I dont want to use open-jdks.
When I type java -version or javac -version, both the times it returns that it is using openjdk and its jre. How can change it to jdk1.7.0?
Put something similar to following to your ~/.bashrc
export JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
export PATH="$JAVA_HOME/bin:$PATH"
for loading the changes, you can just run new bash by typing "bash" :]
Change the PATH variable so that /usr/lib/jvm is listed before the directory which contains Open JDK. If you are using bash, you can do this in the .bashrc file in your home directory.

Categories

Resources