[CentOS] Error: Could not find or load main class with OpenJDK and Oracle Java

Fri Jun 17 10:48:16 UTC 2016
Alexander Farber <alexander.farber at gmail.com>

Hello fellow Linux users,

on CentOS 7.2 I have successfully downloaded and installed Oracle Java [1]
with:

    # rpm -Uvh jdk-8u91-linux-x64.rpm

Also there is already OpenJDK installed:

    # rpm -qa | grep -i jdk
    java-1.8.0-openjdk-headless-1.8.0.91-0.b14.el7_2.x86_64
    java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64
    jdk1.8.0_91-1.8.0_91-fcs.x86_64

I can switch between the 2 using this command:

    # alternatives --config java

    There are 2 programs which provide 'java'.

      Selection    Command
    -----------------------------------------------
    *  1
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64/jre/bin/java
     + 2 /usr/java/jdk1.8.0_91/jre/bin/java

    Enter to keep the current selection[+], or type selection number:

And see the selected version with:

    # java -version
    java version "1.8.0_91"
    Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
    Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

    # javac -version
    javac 1.8.0_91

Now to my problem please -

I have created a simple java file named TheClassName.java:

    package thepackagename;

    public class TheClassName {
            public static final void main(String[] args)  {
                    System.out.println("Hello World!");
            }
    }

After successfully compiling it with "javac TheClassName.java"
(which produces TheClassName.class file in the same dir)
I unfortunately can not run it:

    # java -cp . thepackagename.TheClassName
    Error: Could not find or load main class thepackagename.TheClassName

Here another try:

    # export
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64/jre

    # $JAVA_HOME/bin/java -cp . thepackagename.TheClassName
    Error: Could not find or load main class thepackagename.TheClassName

Setting another environment variable does not help either:

    # export CLASSPATH=.

Similar command on Windows 7 works well and I have tried
copying the TheClassName.class file from there to Linux too.

The setting is SELINUX=disabled and the server
was installed few weeks ago, serving (without errors) as
LAMP with MySQL/PostgreSQL/Apache/WordPress.

Any suggestions please, have I missed anything?

Regards
Alex

  [1]: http://www.oracle.com/technetwork/java/javase/