Can't run java applications - java

I have trouble when trying to open my jar files with the following command:
java -jar software.jar
They load until a certain point and then nothing happens.
I deinstalled default-jdk and OpenJDK with synaptic and re-installed it with apt-get, but nothing changed. I had a similar problem one month ago and solved it (apparently only temporarly) by deleting the package gcj-5-jre-lib (5.4.0-6ubuntu1~16.04.4) (Java runtime library for use with gcj (jar files))
The following outputs will help:
java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
javac -version
1.8.0_131
My variables $JAVA_HOME and $JRE_HOME were correctly added to my $PATH.
I'm on Ubuntu 16.04
EDIT
Here is an example of what I get when I try to start PhyDE.jar
java -jar PhyDE.jar
Welcome to PhyDE 0.9971!
Reading preferences.
Creating PhyDE-Application window
Checking for updates...
You are using the latest version of PhyDE
Done with checking for updates
When checking the core use with the command top I see that the process is active, but the user interface does not open as it usually does. I am located in the folder where the jar file is, and same happens with other jar files.

Related

Cannot set up SDK for IntelliJ Idea

I am beginner in linux (running Linux Mint 18.3), and trying to set-up my environment for Java development. I've done this several times on my Windows machine, and it always worked, but couldn't make it work for linux.
Running command java-version returns the following:
openjdk version "1.8.0_162"
OpenJDK Runtime Environment (build 1.8.0_162-8u162-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.162-b12, mixed mode)
Still, when I open IntelliJ, it says that Project SDK is not defined. When I am trying to set it up to the folder /usr/lib/jvm/java-8-openjdk-amd64/jre/bin (being the location I found digging into my filesystem starting with command whereis java) it says that "The selected directory is not a valid home for JDK". I've added manually the path also to $JAVA_HOME and '$PATH' but the problem persists.
The path you posted says "jre" in it, you need the JDK.
You need shoose JDK path
without BIN folder, like D:\java\jdk\jdk1.8.0_162

Getting "Error: Could not find or load main class " when invoking a JAR from a bash script

I built and ran a JAR on machineA as follows:
java -cp /foo/lib/dep1.jar:/foo/lib/dep2.jar:/foo/export/myjar.jar foo.bar.baz.MyMainClass ...
So myjar.jar is the JAR I built and the other two its dependencies. Ran without any issues.
I then wanted to do the same on machineB so I copied the 3 JAR files there, then tried:
/non/default/install/java -cp /bar/dep1.jar:/bar/dep2.jar:/bar/myjar.jar foo.bar.baz.MyMainClass ...
and got Error: Could not find or load main class. (NOTE: /non/default/install/java is a separate java install on machineB that I have to use instead of /usr/bin/java. Reason is "historical", i.e. I have no control over this)
On machineA, java -version gives
java version "1.7.0_91"
OpenJDK Runtime Environment (rhel-2.6.2.2.el6_7-x86_64 u91-b00)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
On machineB, /non/default/install/java -version gives
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
Both machines are running RedHat 6.
Why am I getting the error and how do I fix it?
Thx!
IMPORTANT UPDATE: I ran the commands below from command line on machineA. On machineB I originally ran them using a bash script. This means that I put them into run.bash and then ran bash run.bash from the command line. That's when I got the error. When I reran the same command from command line without using any scripts, it worked. So it seems that the problem had nothing to do with me copying the JAR form one machine to another but rather with the fact that I was invoking them form a script. And so the question really is now: how do I modify run.bash and/or the way I execute it to get rid of the error? (cuz I do need to use a script eventually)

How to change the version of Java that CDH uses

I currently have CDH 5 installed on CentOS 6.5 with java jdk1.7 and I am trying to get CDH to use jdk1.8.
I do know that Java 1.8 is not a recommended version of CDH, but it is only a test cluster, so it isn't a big deal.
I have installed both Java 1.7 and Java 1.8 from Oracle's website using the RPM installation, so both versions of Java are currently under /usr/java. Using ls -ld my Java directory looks like:
/usr/java/default -> /usr/java/latest
/usr/java/jdk1.7.0_75
/usr/java/jdk1.8.0_31
/usr/java/latest -> /usr/java/jdk1.8.0_31
I also have script set up in /etc/profile.d to set $JAVA_HOME to /usr/java/default. The contents of my profile.d script:
export JAVA_HOME=/usr/java/default
export PATH=${JAVA_HOME}/bin:${PATH}
So when felt that I have this right, I run:
$ which java
/usr/java/default/bin/java
Telling me that it is pointing to the version of Java symlinked in default. And to determine which version of java is running, I run:
$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
And I can see that I have Java 1.8 currently running.
Everything seems great, except when I try to start a Hadoop service. The easiest to start is ZooKeeper, because it only has one service. HDFS has multiple servers so it is more work that to just start and stop ZooKeeper.
Starting ZooKeeper is done with the following command:
$ sudo service zookeeper-server start
Then to check which version of java it is running, I search the running processes list for java:
$ ps -ef | grep java
495 7170 1 7 12:27 ? 00:00:00 /usr/java/jdk1.7.0_75/bin/java -Dzookeeper.datadir.autocreate=false -Dzookeeper.log.dir=/var/log/zookeeper -Dzookeeper.root.logger=INFO,ROLLINGFILE -cp /usr/lib/zookeeper/bin/../build/classes:/usr/lib/zookeeper/bin/../build/lib/*.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12-1.7.5.jar:/usr/lib/zookeeper/bin/../lib/slf4j-api-1.7.5.jar:/usr/lib/zookeeper/bin/../lib/netty-3.2.2.Final.jar:/usr/lib/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/lib/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/lib/zookeeper/bin/../zookeeper-3.4.5-cdh5.3.0.jar:/usr/lib/zookeeper/bin/../src/java/lib/*.jar:/etc/zookeeper/conf::/etc/zookeeper/conf:/usr/lib/zookeeper/*:/usr/lib/zookeeper/lib/* -Dzookeeper.log.threshold=INFO -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /etc/zookeeper/conf/zoo.cfg
I know that runs off the screen, bu the important part is that Zookeeper is being started by /usr/java/jdk1.7.0_75/bin/java.
To fix this, I have tried a few things:
Looking at the conf files for Hadoop and ZooKeeper under /etc/hadoop/conf and /etc/zookeeper/conf, respectively.
I found nothing setting JAVA_HOME.
Looking at the /usr/bin/zookeeper script to see if JAVA_HOME was set elsewhere,
I did find the script /usr/lib/bigtop-utils/bigtop-detect-javahome has the ability to set JAVA_HOME, but my profile.d script overrides that.
Manually moving /usr/java/jdk1.7 to /tmp.
Sadly, this is the only thing that works. When I move the jdk1.7 dir to another directory, and start ZooKeeper, it will use Java 1.8. Moving the jdk1.7 dir back, reverts to ZooKeeper using Java 1.7.
Has anyone dealt with this problem and does anyone know how to deal with this? I feel that I have Java set up correctly, but something is telling ZooKeeper/Hadoop to use an old version of Java?
I came here because I was looking for ways to upgrade JDK from 1.7 to 1.8 on the latest Coudera QuickStart VM 5.8 (can't believe they still ship it with JDK1.7 by default!). The hints and suggestions in the above answers helped tremendously - but since they were not listing complete steps to achieve the upgrade - I thought I would add that to help others like me.
So, here is a complete set of steps to upgrade Cloudera QuickStart VM from JDK1.7 to 1.8:
check your current JDK version - out-of-the-box it is:
[cloudera#quickstart ~]$ java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
download desired version of JDK1.8.xx - in my case: jdk-8u111-linux-x64.tar.gz
as user 'cloudera':
untar and move the resulting jdk1.8.0_111 dir to the /usr/java dir:
tar xzf jdk-8u111-linux-x64.tar.gz
sudo mv -f jdk1.8.0_111 /usr/java
shutdown all Hadoop services:
$ for x in `cd /etc/init.d ; ls hadoop-*` ; do sudo service $x stop ; done
update bigtop-utils file - set JAVA_HOME to your new JDK:
sudo vi /etc/default/bigtop-utils
updated lines:
# Override JAVA_HOME detection for all bigtop packages
export JAVA_HOME=/usr/java/jdk1.8.0_111
update 'cloudera' user's .bash_profile - export JAVA_HOME and add update PATH:
export JAVA_HOME=/usr/java/jdk1.8.0_111
PATH=$JAVA_HOME/bin:$PATH:$HOME/bin
export PATH
restart your VM
check Java version - should be the 1.8 one now:
[cloudera#quickstart ~]$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
By the way, I did not setup the /usr/java/default with the 'latest' sym link as #milk3422 did, for the sake of simplicity, but it would have worked just as well.
thanks!
I hate to answer my own questions, but here is the answer:
The wrong version of $JAVA_HOME is getting set for 2 reasons:
Using the command service removes most environmental variables. From man service:
service runs a System V init script in as predictable environment as
possible, removing most environment variables and with current work-
ing directory set to /.
The /usr/lib/bigtop-utils/bigtop-detect-javahome script has the ability to be configured with the environment variable BIGTOP_JAVA_MAJOR to manually set which version of Java to use. I tried setting this as an environment variable, but service removes it :(. It is also important to note that this script will find all versions of java installed, but the order of preference is Java 6, Java 7, Java 8, Open Java. So if you have Java 6, and 8 installed, it will prefer 6 over 8.
In short, to fix my problem, I added the following to the top of /usr/lib/bigtop-utils/bigtop-detect-javahome:
BIGTOP_JAVA_MAJOR=8
You can also set JAVA_HOME in this file to specify a specific version or path.
I had the same problem. I set
JAVA_HOME=... below the file /usr/lib/bigtop-utils/bigtop-detect-javahome
to override the default detect value. That works great!
Java is configurable in the web UI. Open Cloudera Manger --> Hosts --> Configurations --> Advanced, then set the JAVA HOME. This overrides the CDH's Java detection mechanism.

Open MPI's Java bindings

I'm trying to build the new Java bindings of Open MPI (v.openmpi-1.9a1r29661) on Macbook Pro running Mavericks (OSX 10.9). I have the JDK 7 installed:
^_^:examples demirelo $ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
I configured the OMPI with that command:
./configure --enable-mpi-java --with-platform=optimized --with-jdk-dir=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home --prefix=/Users/demirelo/libs/openmpi
which is followed by the usual suspect:
make all install
When I tried to run the HelloWorld example, I received the following runtime error:
^_^:examples demirelo $ ../bin/mpijavac Hello.java
^_^:examples demirelo $ ../bin/mpirun -np 1 java Hello
JAVA BINDINGS FAILED TO LOAD REQUIRED LIBRARIES
-------------------------------------------------------
Primary job terminated normally, but 1 process returned
a non-zero exit code.. Per user-direction, the job has been aborted.
Moreover, the ~/.bash_profile has the correct path to the /lib folder.
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Users/demirelo/libs/openmpi/lib/
It's quite mysterious which libraries failed. Previously, I was able to build slightly older version (openmpi-1.9a1r28578) on Lion and still use it on Mavericks. This time I needed a freshly compiled OMPI but didn't work out. I'm wondering if anyone else had the same issue with Mavericks and was able to fix it.
This appears to be a bug in Open MPI that is comprised of at least two issues:
OMPI is hard-coded to try to dlopen libmpi.so, which is the wrong name on OS X (it should be libmpi.dylib).
Even after I fix that, I'm running into another Java error that I need to run by the Java programmers.
Apparently, we haven't tested the OMPI Java bindings on OS X in a long time. :-(
Such is the life of running against the SVN trunk. Sorry!

Cygwin runs wrong version of java

I have this problem with Cygwin. I have Java 1.6 and 1.7 installed. I want to use maven 3.0.4 with Java 1.7 but I don't want to uninstall Java 1.6. My JAVA_HOME looks like:
C:\Program Files\Java\jdk1.7.0_09
when I run
java -version
in Cygwin I get:
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)
when I run the same command in cmd.exe I get:
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
Does anyone knows how to solve this?
There are two separate questions here.
The first question is why java -version is finding different Java installations on Cygwin and the classical Windows command interpreter.
The answer is most likely that your Cygwin and Windows environments have different values for $PATH and %PATH% respectively. If you want java -version on Cygwin to run Java 7, you need to make sure that the Cygwin $PATH includes the Java 7 bin directory ... in the appropriate syntax.
The second question is how to get the mvn command under Cygwin to use Java 7.
The answer is not so straight-forward:
Setting $PATH might solve your problem.
According to the Maven installation documentation, the mvn wrapper scripts should use the $JAVA_HOME environment variable in your (Cygwin) shell to decide on which Java to use.
The way to find out what is really going on is to look at the wrapper scripts and see what they are actually doing. And if reading the scripts is too hard, try "hacking" the scripts to include set -vx. That will tell you what lines of the script are being read, and what commands are being executed.
Finally, the POM file can influence the source and target levels for your build ... independently of the JVM that runs the build.

Categories