Java 7 or 8 is required to Run .Jar (Linux) - linux

This is a newly installed centos 6.2 x86_64 I have downloaded java 8u5 rpm for linux to run a .jar file, but I am unable to. I have removed java through terminal through the command "rpm -e jar-1.8.0_05", and have attempted to reinstall it, though I still get the same error. I have also attempted to install java 7u60, but I still get the same error.
I am now on java 8u5, trying to find a fix for this.
Image:
http://i.stack.imgur.com/f0kzk.png

Try running
cd <path to jar file>
/user/java/jre1.8.0_05/bin/java -jar <jarname>

Related

sdkman on cygwin can't install

I'm setting up a new machine and installing sdkman on Cygwin to install Java. I had this exact setup working on my previous machine, also Win 10.
Installed Cygwin, and required for sdkman, installed zip and unzip packages. Now I'm getting the following error:
$ sdk i java 11.0.3-zulu
Downloading: java 11.0.3-zulu
In progress...
Warning: Failed to create the file
Warning: /home/whyph/.sdkman/tmp/D2txrZkztdcZKSIltTtxclUhHkzF9yIf.bin: No such
Warning: file or directory
curl: (23) Failed writing body (0 != 14095)
mv: cannot stat '/home/whyph/.sdkman/tmp/D2txrZkztdcZKSIltTtxclUhHkzF9yIf.bin': No such file or directory
Tried disabling Windows firewall and running Cygwin as administrator, neither changed the error. Worked out of the box on my last machine, but can't figure out what might be different.
I discovered the problem - wrong curl. Turns out, Windows 10 now comes with curl and it's on your path. I assumed it was one of the base packages of Cygwin, but it is not, and the Windows version is not compatible with SDKMAN, even though it worked to install it. Fix:
Remove SDKMAN per https://sdkman.io/install Uninstallation section
Close Cygwin shells
Rerun Cygwin setup and insure the curl, zip, unzip, and tar packages
are installed (check installation instructions in case more
dependencies are added since this writing)
Install SDKMAN per instructions
Recently I had the very same problem, and the reason was very simple... I forgot to install cURL on my Cygwin. Hope it helps!
I had the same problem recently and I manage to make it work somehow.
In the sdkman source file, I modified the .sdkman/src/sdkman-install.sh line 150.
I replaced the "--output" of the line below by a classic redirection ">".
After I just restarted cygwin and the command finally worked.
__sdkman_secure_curl_download "${download_url}" --output "${binary_input}"
Hope that helps !

Intellij IDEA 2017.2 can't add openjk 9 on Linux Mint 18

I am using Intellij IDEA 2017.2.5 on Linux Mint 18.2 and trying to add new openjdk-9 SDK but IDEA does not accept openjdk 9 as valid JDK:
I have installed all of my SDKs using apt-get from ppa standard repositories.
This is my update-alternatives --config java/javac output:
Although Intellij declared it would support JDK 9 here, but it seems it is not yet fully compatible with at least opensdk-9.
Maybe refactoring SDK directory and removing 'jre' folder misleads the IDEA to find the SDK 9 home folder.
Any idea why Intellij IDEA claims 'The selected directory is not a valid home for JDK' ?
“ Ubuntu PPA for OpenJDK” currently has very old build of openjdk-9(9~b115-1ubuntu1).
So the IDEA does not recognize it as a valid SDK.
I removed current installed version:
sudo apt-get remove '^openjdk-9.*'
Then I have downloaded newer .deb build(9~b181) files including jre,jre-headless,... from launchpad build archive.
sudo dpkg -i openjdk-9-jre-headless_9_b181-4_amd64.deb
openjdk-9-jre_9_b181-4_amd64.deb
openjdk-9-jdk-headless_9_b181-4_amd64.deb
openjdk-9-jdk_9_b181-4_amd64.deb
Just Execute the above command at a single line, line breaks are for better readability.
Ignore any error complaining about:
"Package libpng16-16 is not installed."
Next execute the following:
sudo apt-get install -f
Now after installing this build of openjdk-9 the IDEA is happy with SDK home.
Thanks #y.bedrov for his useful comment.
Update:
However this solution enables you to declare openjdk-9 in the mentioned IDEA version(2017-2) but you are not able to compile any class within the IDEA itself.
You can only compile your application with elder jdk and run it with openjdk-9. There is an other issue which indicates this here.
In the newer IDEA versions(I have tested 2017.3) this build of openjdk is not allowed to be used as new SDK any more, see this issue.
The short reason is an issue in Debian package which contains incorrectly compiled lib/jrt-fs.jar file.
See this Answer for more information

Issue with Netbeans on Linux Mint

I just installed Netbeans using the script on Oracle's website and I'm having some trouble getting it to work. After opening Netbeans I went to open up a simple .java file just to test it out and got this error:
"The JDK is missing and is required to run some Neatbeans modules. Please use the --jdkhome command line option to specify a JDK installation or see http://wiki.netbeans.org/FaqRunningOnJre for more information."
I have OpenJDK, and I'm not sure what's meant by using the --jdkhome command line option. I also visited the wiki and it's about doing a full installation of JDK, which I don't think I should need to do. Any help is appreciated.
I think it's better to use Oracle Java JDK rather than Open JDK if you want to use Netbeans for java development
You can use this link to set Oracle Java JDK in Linux Mint
So, it's better to follow theses instructions (JDK install) prior to Netbeans install and all things will go well.
Steps:
1-Remove OpenJDK installation
sudo apt-get update && apt-get remove openjdk*
2- Download Oracle JDK you want to install (for example JDK 8)
Download the *.tar.gz one.
example for current version: jdk-8u65-linux-x64.tar.gz
3- Extract the file and create a folder where to move it
tar -zxvf jdk-8u65-linux-x64.tar.gz
sudo mkdir -p /opt/java
sudo mv jdk1.8.0_65 /opt/java
4- Make JDK system default
sudo update-alternatives --install "/usr/bin/java" "java"
"/opt/java/jdk1.8.0_65/bin/java" 1
sudo update-alternatives --set java /opt/java/jdk1.8.0_65/bin/java
At this stage, you can start the installation of Netbeans IDE and it will automatically detect your Oracle JDK setting
I tested a short HelloWorld Java example, and I don't have any issue.
Here is the setting JDK view in Netbeans:
If you want to add the JAVA Home dir to your system
Proceed like this
You have to be in root mode and then edit this file: /etc/bash.bashrc
and add:
#JAVA HOME
JAVA_HOME=/opt/java/jdk1.8.0_65
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
Reboot your Mint system
Now you'll have javac working in command line...

How do I configure Oracle Java JDK 7 (not Open JDK) correctly on Ubuntu 11.10 and run a Java Program with referenced JAR files?

I may have multiple questions here, but ultimately I'm trying to compile and run a Java program that references 3rd party JAR files (on Ubuntu Linux) so I thought it was appropriate to keep it to one question.
I'm trying to get Java JDK 7 properly installed and configured to run a simple program on Ubuntu Linux. I'd like to get instructions from an expert that can help me, at the very least, to run a simple Java program from the command line (perhaps a "Hello World" application?). I've only compiled and run Java programs on Windows in the past, so this is new to me. Last night, I read that you have to be careful of not installing the Open JDK, and to install the Oracle JDK. It appears that Ubuntu 11.10 installs Java Open JDK for you when the OS is installed, among others.
I'm running 32-bit Ubuntu, not 64-bit. So I downloaded this Linux JDK file:
jdk-7u4-linux-i586.tar.gz
I unpacked the tarball into /usr/java and then deleted the *.gz file to save disk space. Some tutorials say to install into /usr/java and some say to install into /usr/lib/jvm, so I just picked one and rolled with it. If you have a suggestion on the appropriate install directory, please let me know what you suggest.
I then checked what Java version was installed (below) with the "java -version" command. It did not find the Oracle JDK.
(1) Why didn't the command list the Oracle JDK package I just installed?
mac#UBUNTU:/usr/lib$ java -version
The program 'java' can be found in the following packages:
* gcj-4.4-jre-headless
* gcj-4.6-jre-headless
* openjdk-6-jre-headless
* gcj-4.5-jre-headless
* openjdk-7-jre-headless
Try: sudo apt-get install <selected package>
mac#UBUNTU:/usr/lib$
(2) Can you help me with the steps necessary to configure this Linux machine to compile a Java program (finish what I just started)?
(3) Can you help me with the steps to compile a *.java file to create the *.class file?
(4) Can you help me run the Java program--the one we just compiled?
(5) Suppose I want to include multiple *.jar files (3rd party assemblies) in my Java program. How does Java know on Linux where to find these files if they are not in the directory running the Java program referencing them? (I'm only familiar with a CLASSPATH in Windows)
Ubuntu is based on Debian and its apt-get utility. apt-get will list only known packages. The one you installed is just a folder lying on your system and apt-get does not even know about it.
It looks like java is not on your path. So either you create a symbolic link to the java binary in one of the folders of your path (type env to see what's in your path variable), or you add the JDK bin directory to your path (see command export). As a last resort, you can type the absolute path to the java binary, but that's just painful.
To compile, you simply use javac (Java compiler). For example javac Test.java. Make sure that javac is also on your path (or use the absolute path to the java compiler)
To run it, type java -cp . Test (don't forget to type the fully qualified name of your class if you put it inside a package, which is recommended)
When you compile or when you run, use the argument -cp followed by the list of jars you want to use (separated by a ':' on Linux and by a ';' on Windows). You may use wildcards in your classpath (like lib/*.jar) but you may also have to escape the wildcard to avoid shell expansion (like this lib/\*.jar).

installing java in linux issues

Im trying to install Java in install but for some reason its not working.
I tried the same way as mentioned in this website-http://www.java.com/en/download/help/linux_install.xml#enable
I see Java installed in my desktop when I try this command,
premvidya#ubuntu:~/Desktop$ ls
jre1.6.0_31 jre-6u31-linux-i586(2).bin jre-6u31-linux-i586.bin
but when I try java - version, I get the following error,
premvidya#ubuntu:~/Desktop$ java -version
The program 'java' can be found in the following packages:
* gij-4.3
* java-gcj-compat-headless
* openjdk-6-jre-headless
* cacao
* gij-4.2
* jamvm
* kaffe
Try: sudo apt-get install
bash: java: command not found
Any help would be appreciated.
Why are you trying to manually install java? There is a repository for this, and it's all managed for you. Uninstall whatever you have put on your system manually and install it via command line.
apt-get cache search java
apt-get cache search jdk
or
start Ubuntu Software Center -> search for java.
Once installed via apt-get, the new java commands will be available immediately in your PATH, so long as you haven't removed anything...
#user1050619
Hi user1050619,
I have come across the solution which will work on any version of Ubuntu definitely keeping other java versions intact.
I have used standalone installation of Java.
For this, please download tar.gz version of Java from
Oracle website.
Suppose, your jdk installation tar file at location /home/don/
don#ubuntu ~ $ tar zxf jdk-7u45-linux-i586.tar.gz
don#ubuntu ~ $ sudo bash
[sudo] password for don:
ubuntu ~ # mv /home/don/jdk1.7.0_45/ /usr/lib/jvm/
ubuntu ~ # cd /usr/lib/jvm/
ubuntu jvm # update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_45/bin/java 3
ubuntu jvm # update-alternatives --config java
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java 1071 auto mode
1 /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java 1071 manual mode
2 /usr/lib/jvm/jdk1.7.0_45/bin/java 3 manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/jdk1.7.0_45/bin/java to provide /usr/bin/java (java) in manual mode
ubuntu jvm # java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)
and you are done here without any hassles.
Happy programming !!
it should be "apt-cache search java6" or just "apt-cache search java". It'll give you a list of all the package related to java. If you want to install sun's java then you download the java-**.bin file like you did and then run "sudo /bin/sh jre-6u31-linux-i586.bin" That'll run the installer from the sun java you downloaded and begin to install. Answer the question and install the package.

Resources