Alexander Farber
2016-Jun-17 10:48 UTC
[CentOS] Error: Could not find or load main class with OpenJDK and Oracle Java
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/
Alexander Farber
2016-Jun-17 12:09 UTC
[CentOS] Error: Could not find or load main class with OpenJDK and Oracle Java
Nevermind, I had to move my test file under thepackagename/TheClassName.class and then it runs fine. However my real program [1] consisting of few jar-files still does not run on CentOS (while running fine on Windows). I have to investigate more and will ask a separate question. Regards Alex [1]: https://github.com/afarber/jetty-newbie/tree/master/WebsocketHandler
Possibly Parallel Threads
- CESA-2016:0650 Critical CentOS 7 java-1.8.0-openjdk Security Update
- CEBA-2016:1306 CentOS 7 java-1.8.0-openjdk BugFix Update
- CentOS-announce Digest, Vol 134, Issue 11
- CEBA-2016:1877 CentOS 7 java-1.8.0-openjdk BugFix Update
- CESA-2016:0651 Critical CentOS 6 java-1.8.0-openjdk Security Update