RIght JVM folder for IDE - java

Typing cd /usr/lib/jvm from shell I see the following:
default-java java-1.6.0-openjdk-i386 java-6-openjdk-common
java-1.5.0-gcj-4.6 java-1.7.0-openjdk-i386 java-6-openjdk-i386
java-1.6.0-openjdk java-6-openjdk java-7-openjdk-i386
can someone explain what's the difference between java-1.x.. and java-x-openjdk folders?
More specifically, when I want to set default jdk in Netbeans or Eclipse, which folders should I use out of those two types?

Although I cannot tell for sure, but I suspect that all the java-6-* are soft links to java-1.6.0-openjdk-i386. Likewise, all the java-7-* are soft links to java-1.7.0-openjdk-i386.
If you want to tell for sure, do ls -l so you can see the details of the files, including what they are links to.
If you still need Java 5, 6 and 7 (even though they are EOL) then you can add any of the paths (linked or not) to Eclipse.
As for which should be your default, install Java 8 and set that up as the default. The best way on Ubuntu is probably this way (see docs):
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Related

Could not find or load main class com.nabinbhandari.lam.Main

I've read a lot of troubleshooting for similar occurrences of this error, but what is causing it for this particular .jar?
https://download.cnet.com/android/nabin-bhandari/3260-20_4-10982661-1.html
It works on Windows, but when attempting to run the file on a raspbian (linux) system running java version 1.8.0_65 with the command java -jar Local\ Area\ Messenger\ Desktop.jar it throws the error about not being able to find or load the main class.
The MANIFEST.MF defines Main-Class: com.nabinbhandari.lam.Main and there doesn't appear to be any issues with case sensitivity.
What am I missing? Do I need to install something more than Java Runtime Environment?
Edit: In case it is not clear, I am not the developer of this file. I am simply a user trying to run the file. This question has nothing to do with Eclipse and I don't understand why people are linking to that other question. I am not running Eclipse. Please stop linking to that. Please examination the .jar file I have provided.
Edit 2: I have followed the instructions and in this answer:
https://stackoverflow.com/a/1238173/2407742
It gives the error no main manifest attribute, in test.jar
Is there something missing from my java runtime environment? It seems like nothing works.
The Local Area Network Messenger application was developed using JavaFX, which is not included in the Oracle Java build for Rasperry Pi. I had to reinstall Java and then openjfx by doing the following:
sudo apt-get purge openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre
sudo apt-get install openjfx
It runs fine now.
The solution to this was the following:
Close Eclipse/STS
Use a file explorer on your operating system to navigate to your workspace (In my case, I'm on Windows so I used Windows Explorer)
Delete the .metadata directory (or to be safe, copy the directory somewhere else to be safe, then delete it)
Restart Eclipse/STS
Is there a more improved answer than this? I don't want to look like I'm trying to boost my own reputation points, so if someone can provide a better answer then please do so.

apt-get installing oracle java 7 stopped working

Recently apt-get install -y oracle-java7-installer stopped working.
I know in their roadmap, I think the public version is no longer supported, but it's been working all the way until recently.
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Anyone have a work around for this?
http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz?AuthParam=1495560077_4041e14adcb5fd7e68827ab0e15dc3b1
Connecting to download.oracle.com (download.oracle.com)|96.6.45.99|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-05-23 10:19:17 ERROR 404: Not Found.
It appears Oracle has moved the download link, you can still fetch the tar ball from the oracle website after jumping through some hoops. The WebUpd8 installer is currently broken. The official explanation can be found at http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html
Download Method 1: Login into to Oracle site
The link now seems to be: http://download.oracle.com/otn/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz
notice "otn" and not "otn-pub", but at least from the website you seem to need to be signed in and not only accept the license agreement.
It may be possible with debconf to change the url from otn-pub to otn and get the installer to work but I haven't tried. You can fetch the binary yourself and either install manually or with the installer pointing it to wherever you put the downloaded tar ball.
Edit: It seems there isn't a way to configure download URL (though you can hijack it with hosts as in another answer).
Download Method 2: Use a trusted mirror
If you want to download jdk-7u80-linux-x64.tar.gz from a script without logging into to oracle it hosted locations include:
http://ftp.osuosl.org/pub/funtoo/distfiles/oracle-java/
http://ftp.heanet.ie/mirrors/funtoo/distfiles/oracle-java/
EDIT: The sha256 has been removed from this answer because (as this edit demonstrates) anyone can edit said hash. Get your hashes from a trusted source. Suggestions include:
https://www.oracle.com/webfolder/s/digest/7u80checksum.html
Install Method 1: Prepopulate cache
#put the file in the default cache location:
sudo mv jdk-7u80-linux-x64.tar.gz /var/cache/oracle-jdk7-installer/
#then install normally:
sudo apt-get install oracle-java7-installer
Install Method 2: (more elegant IMHO) put tar ball anywhere and tell the installer where to look
#setup ppa (you probably came here after already doing this)
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
#put the file in a temporary location:
sudo mv jdk-7u80-linux-x64.tar.gz /tmp/
#set local path to /tmp (or any other path)
echo oracle-java7-installer oracle-java7-installer/local select /tmp | \
sudo /usr/bin/debconf-set-selections
#While your at it you may want tp approve license (or skip this and approve when prompted)
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | \
sudo /usr/bin/debconf-set-selections
#then install normally:
sudo apt-get install oracle-java7-installer
So looks like the direct links to the download no longer work( As noted by Meir Maor above)
Here are the steps to get this running again:
Go to http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html and accept the license. Download the file we need (jdk-7u80-linux-x64.tar.gz in this case)
Assuming the file downloaded to your Downloads directory, we need to move it to /var/cache/oracle-jdk7-installer
cd ~/Downloads (Change to directory to which you saved file from step 1)
sudo mkdir /var/cache/oracle-jdk7-installer
sudo mv jdk-7u80-linux-x64.tar.gz /var/cache/oracle-jdk7-installer/
Not sure if necessary but I had luck with this:
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
Run the installer now. It will use the file we saved in /var/cache instead of trying to download it from Oracle
sudo apt-get install oracle-java7-installer
I got step 3 from http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
I just ran into this trying to install Java 6 (don't ask).
Since I'm short on time, I was fine with a quick and dirty answer. I noticed the URL looked for by the installer was http-based (vs https), which makes the below solution possible.
Make sure a web server is installed (I already had Apache on my box)
Download the file that is requested. In your case that is
jdk-7u80-linux-x64.tar.gz. See Meir Maor's answer above
On your local web server, recreate the path structure requested for the
file. In your case that is otn-pub/java/jdk/7u80-b15.
Copy the downloaded file into the path above
Edit /etc/hosts and add 127.0.0.1 download.oracle.com
Run apt-get install -y oracle-java7-installer again.
The installer will now grab the file from your local web server and complete successfully.
There may be a better way to do this, but it worked for me.
As Oracle support for debian packages has gone quite a while ago, I suppose that you use the method of webupd8
Go to their instructions I linked before and check if your configuration is still valid.
They also provide a method to install Java 8: Install Oracle Java 8 in Ubuntu (Debian instructions linked from there.)
Edit: I think that Oracle does not provide a public download of Java 7 anylonger - you would have to download it from the Java Archive. (http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html)
You could try to download the rpm package and use alien to convert it to a .deb package. And did you already consider updating to Java 8?
You can find the webupd8team ppa's online. The oracle-java7-installer has the version number "7u80+7u60arm-0~webupd8~1" I'm guessing this defect would occur for all the provided ubuntu versions!
Looking in one of the ppa's a few of the files directly reference the broken url identified by Meir Maor
debian/oracle-java7-unlimited-jce-policy.postinst:PARTNER_URL=http://download.oracle.com/otn-pub/java/jce/7/$FILENAME
debian/oracle-java7-unlimited-jce-policy.config:PARTNER_URL=http://download.oracle.com/otn-pub/java/jce/7/$FILENAME
debian/oracle-java7-installer.config: PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/7u80-b15/$FILENAME # Must be modified for each release!!!
debian/oracle-java7-installer.config: PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/7u60-b19/$FILENAME # Must be modified for each release!!!
debian/oracle-java7-installer.postinst: PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/7u80-b15/$FILENAME # Must be modified for each release!!!
debian/oracle-java7-installer.postinst: PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/7u60-b19/$FILENAME # Must be modified for each release!!!
unfortunately I can't figure out how to lodge a defect with them (yet) but presumably this would be a quick fix

Set PATH and JAVA_HOME in Fedora 25

Please excuse what appears to be a question answered before, but if I read 10 different posts I find 20 different responses.
I just installed Fedora 25. I am going to be learning Java development and need to set up my environment. I will be using openjdk and have installed java-1.8.0-openjdk-devel. I will also be using Maven.
Now I need to set my $PATH and $JAVA_HOME variables.
I tried the answer found here (Fedora OpenJDK Set JAVA_HOME)
but after adding to my .bashrc
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and then testing, I get what appears to me to be the wrong answer because I do not think there should be a /jre/ on the end
> echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-1.b14.fc25.x86_64/jre/
So can I please ask what I should set JAVA_HOME to so that I do not need to update it with every openjdk update?
After that I think PATH is just
export PATH=$JAVA_HOME/bin:$PATH
this seems like such a straightforward thing to do yet it seems to me there is much confusion. thx
PS
also, is .bashrc even the correct place? because I see here (https://askubuntu.com/questions/175514/how-to-set-java-home-for-java) that /etc/environment would be more appropriate) thx
I suggest create an alias command, modifying bashrc and set JAVA_HOME
into bash_profile, this:
Create command in the bashrc:
alias set-java='sudo alternatives --config java;export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::");source ~/.bash_profile'
Save and execute: source ~/.bashrc
Create generic JAVA_HOME in bash_profile:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
PATH=$JAVA_HOME/bin:$PATH
Execute the alias command
Set JAVA_HOME :
echo "JAVA_HOME=/etc/alternatives/jre" >> ~/.profile
source ~/.profile
echo $JAVA_HOME
I put the following in ~/.profile, not ~/.bashrc and I think it's the same on Fedora (I used CentOS at work and do the same):
export JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME=$JDK_HOME/jre
I have to either sign out or reboot after changing .profile.
On Ubuntu, java only changed from 7 to 8 a few years ago. I don't know why Fedora would want to put an exact version number on the java folder. You might complain?
If Java moves around too much for you on Fedora, use a symlink. The symlink takes affect right away, without logging out or rebooting. On my laptop, I encrypt my home folder, so for extra speed, I put most third party tools in a /tools/ folder and give myself account access to it (sudo chown -R myself.myself /tools/ where myself is my user ID). That's where I put my maven install. Tomcat uses a different directory name for each release, so I make a symlink like so:
cd /tools
ln -s apache-tomcat-8.0.38 latest-tomcat
Then in ~/.profile (CATALINA means TOMCAT in this example - don't ask me why):
# My un-encrypted Tools folder
export TOOLS=/tools
# Tomcat
export CATALINA_HOME=$TOOLS/latest-tomcat
# Maven
export M2_HOME=$TOOLS/apache-maven-3.3.9/
export M2="$M2_HOME"bin
export PATH=$PATH:$M2
When I upgrade tomcat:
cd /tools
rm -f latest-tomcat
ln -s apache-tomcat-8.0.39 latest-tomcat
You can use the same technique to make a /usr/lib/jvm/latest-java. In fact, if you install Oracle Java (not necessarily recommended), it does exactly that, for this reason.
Yes, what you said about the path looks correct to me. I don't put java in my path, preferring to use $JDK_HOME, $JAVA_HOME, or just calling maven. Part of that is for security. Part of it is to feel like I always know which version of Java I'm using.
P.S. To me, the ln -s syntax always looks as if the arguments are reversed. The actual folder name goes first, followed by your desired alias/link.
OpenJDK bundled with Fedora dosen't work for me. For example IntelliJ can't use this version. In my opinion, best option is to install Oracle JDK RPM from Oracle.
JDK location:
/usr/java/latest/
To manipilate JRE use command below:
sudo alternatives --config java
So far, this gets Android Studio running using the Fedora provided OpenJDK and respects the distribution provided materials without a bunch of otherwise unmanaged symlinking:
vim ~/.bash_profile
Add the following, or replace any existing examples that look similar to it:
export JAVA_HOME=$(readlink -f /usr/bin/java | cut -d/ -f1-6)
The command basically asks for the physical path that the symlink /usr/bin/java points to (configured by alternatives in Fedora), and then says "take the first 6 fields given to you by splitting on the / character."
Note that your $PATH will already be set up correctly for use with the Fedora provided OpenJDK.
In practice, this ends up looking like:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-8.fc28.x86_64/jre
This assumes you have at least one of the OpenJDK packages Fedora ships. 25 probably only shipped 1.8, 28 ships 1.8, 10.0.2, and 11.0.1. (if you're reading this and still using 25, it's probably time to upgrade.)
Install one of the java-*-openjdk-headless packages available to you (or one of the Oracle provided ones), and configure which one to use using:
sudo alternatives --config java
The default on my Fedora 28 install was to use OpenJDK 1.8.
Sadly I don't have Fedora available for me, so I can't investigate how Java is usually installed, but why you don't try to replace /usr/bin/java in your expression with something like /usr/bin/javac? The actual path to javac link you can get with
which javac
And read the real path with readlink. Obviously, it works if JDK is installed (not JRE).
About updating, most of Linux distros create a symbolic link like /usr/lib/jvm which is set to the correct directory and update in case of new version. For me better solution it to put this path in your bashrc.
And yes, bashrc is usually enough if you don't need JAVA_HOME to be visible to other OS users.
Maybe adding a tr could work? export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::" | tr -d "/jre/") ?
Also, setting it in your env var will make the var independent from the sh your using. That's a great way to store It.

Running programs depending on java not working

I have several programs running on Java that suddenly stopped working.
I ran the commands to start them at command line and nothing happens. When I ran: $java -version nothing happens either.
If a I run: whereis java the output is:
java: /usr/bin/java /etc/java /usr/bin/X11/java /usr/share/java /usr/share/man/man1/java.1.gz
And if I ran wheris {the program depending on java}, I get a similar output. For example, for fastqc software:
$whereis fastqc
fastqc: /usr/bin/fastqc /usr/bin/X11/fastqc /usr/share/fastqc /usr/share/man/man1/fastqc.1.gz
I have no idea what to do. Besides, I checked if java is properly installed by:
apt-get install default-jre
And the output was:
Reading package lists... Done
Building dependency tree
Reading state information... Done
default-jre is already the newest version.
The following packages were automatically installed and are no longer required:
ifeffit libbit-vector-perl libcarp-clan-perl libchemistry-elements-perl
libchemistry-formula-perl libconfig-inifiles-perl libdate-calc-perl
libdate-calc-xs-perl libdate-manip-perl libifeffit-perl libio-stringy-perl
libmath-combinatorics-perl libmath-derivative-perl libmath-round-perl
libmath-spline-perl libntdb1 libole-storage-lite-perl
libparse-recdescent-perl libreadonly-perl libreadonly-xs-perl
libregexp-common-perl libspreadsheet-writeexcel-perl
libstatistics-descriptive-perl libterm-readkey-perl libtext-english-perl
libtext-glob-perl libtie-ixhash-perl libtime-stopwatch-perl
libtk-filedialog-perl libtk-gbarr-perl libtk-histentry-perl libtk-pod-perl
libtk-splashscreen-perl libwwwbrowser-perl libxray-absorption-perl
libxray-scattering-perl linux-image-3.19.0-25-generic
linux-image-extra-3.19.0-25-generic perlindex pgplot5 python-ntdb
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
I also made update, remove and re-install; but nothing changes.
If you have any suggestions please... I am obviously NOT an advanced-informatician...so I do not know what to do.
Thanks!
Have you tried to restart? Usually a nice go to as a first pass at debugging.
Did you not accidentally rewrite your $PATH? i.e. java is still installed, but not in your default path anymore. So running java --version will also fail.
You could also try sudo apt-get install openjdk-7-jdk to install the development kit for java. This also contains jre so might fix things. But my first quess would be your $PATH is broken.
It looks that the problem was the two versions of java that I have installed. The programs I was trying to run needed an older version of java, and when I installed the newer it has been set to use it as default. I finally solved this out, changing the default version of jave to use:
update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1074 auto mode
1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1074 manual mode
Press enter to keep the current choice[*], or type selection number: 1
And that's it!
:)

install Java on ubuntu 15.10

I'm installing Java on Ubuntu 15.10
when I typed sudo add-apt-repository ppa:webupd8team/java
The result
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 95, in <module>
sp = SoftwareProperties(options=options)
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 109, in __init__
self.reload_sourceslist()
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 599, in reload_sourceslist
self.distro.get_sources(self.sourceslist)
File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 89, in get_sources
(self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Ubuntu/xenial
How to fix it? thank you
Just use sudo apt-get install openjdk-8-jdk if OpenJDK also meets your needs (and most probably it will if you aks about "installing Java")
For OpenJDK 8, you should then be able to find your Java executable in /usr/lib/jvm/java-8-openjdk-amd64/bin/java
Why You Going Trough The Hard Way ? .
Just Open Ubuntu Software Center And Search For JDK And Click On Install Button . So Easy
check your sources.list file in /etc/apt/sources.list and make sure the file is not changed or broken .
It looks like that PPA doesn't have anything for Ubuntu 15.10.
I use java-package to convert the tarball from Oracle to a .deb package.
PS. this question is better suited for askubuntu
Well, you need to check if you are behind a proxy??
So you need to set the https_proxy environmental variable to your custom setting, for example:
export https_proxy=http://myproxy.domain.net:8080/
after that, you can run the commnad "sudo add-apt-repository ppa:webupd8team/java"
I don't know why the add-apt-repository doesn't use the proxy settings for apt.
Open Applicaction -> Accessories -> Terminal
Type in the command line as below:
sudo apt-get install openjdk-8-jdk
Type in the command line as below:
apt-cache search jdk
(Note: openjdk-8-jdk is symbolically used here. You can choose the JDK version as per your requirement.)
For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
(Note: "/usr/lib/jvm/java-8-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)
For "PATH" (Environment Variable) type command as shown below, in "Terminal" using your installation path:
export PATH=$PATH:/usr/lib/jvm/java-8-openjdk/bin
(Note: "/usr/lib/jvm/java-8-openjdk" is symbolically used here just for demonstration. You should use your path as per your installation.)
Check for "open jdk" installation, just type command in "Terminal" as shown below:
javac -version

Categories

Resources