2

The environment I'm having a few issues with at the moment is a CentOS6 environment with Java. Previously Java7 was installed, and a recent update to a Java web application was pushed with new features specifically using the Java8 LocalDate.now() function. Naturally Java8 was installed so that it would work - but - it didn't.

I've tried following the OpenJDK 8 installation instructions here (and updating the 'alternatives' too) and this didn't work - https://www.digitalocean.com/community/tutorials/how-to-install-java-on-centos-and-fedora#install-openjdk-8

I've also tried following the installation of Oracle Java 8 version on the same link, which didn't work due to the new annoying licencing issues with Oracle and the commands just kept saying I was unauthorised to download the .tar file.

I'm a bit lost on what to try next. From what I can see, I 'think' the version of Open JDK 8 is the build a few versions before LocalDate.now() was introduced based on;

java -version

command saying;

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

Which looks to be build 25. Yet according to this link, https://coderanch.com/t/716444/java-lang-ClassNotFoundException-Didn-find, it looks like the minimum version of the build is Version 26 to use the LocalDate.now() function.

Ideally I'd like to use the Oracle JDK 8 version to match the development environment, but I can't get that to work either. Oracle is annoying. This is the error message I get when trying to run the commands on the Digital Ocean link around installing the Oracle JDK 8;

Connecting to login.oracle.com|209.17.4.8|:443... connected.
HTTP request sent, awaiting response... 401 Authorization Required
Authorization failed.

Not sure if there is another flag that I need to pass through on the command which includes login credentials, I've not found any guides on this yet.

Update1

Just installed Java8 via AdoptOpenJDK as suggested and configured to use via 'alternatives', the 'java -version' outputs the following;

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
Eclipse OpenJ9 VM (build openj9-0.17.0, JRE 1.8.0 Linux amd64-64-Bit Compressed References 20191017_442 (JIT enabled, AOT enabled)
OpenJ9   - 77c1cf708
OMR      - 20db4fbc
JCL      - 97b5ec8f383 based on jdk8u232-b09)

Yet I'm still seeing the error output in the log files;

java.lang.ClassNotFoundException: java.time.LocalDate

Update 2

Following the recommendation to get back to the real basics, this has helped, but caused more confusion. I've tested;

1) Compiling locally a HelloWorld with a Main method, pushing the .class file to the server and running the file with the java command - which works

2) Creating locally a HelloWorld.java with a Main method, pushing the .java file to the server, compiling on the server with javac to create the HelloWorld.class, and running the file with the java command - which works

3) Creating locally a HelloWorldServlet.java, compiling locally, pushing the .class file to the server, and running /HelloWorld in the browser - which fails and throws the error.

As such, I'm starting to wonder if it's something to do with how Tomcat 7 is setup. It's actually managed by Easy Apache 3 via cPanel's WHM which doesn't help the matter as it's all quite old and really needs a significant upgrade.

It's frustrating because this 'just works' on a standard Linux box with Apache Tomcat installed. I'd ideally like to get this working as-is so I can procrastinate further and avoid having to do a full server re-build, migration and web application setup - but - it's not looking good...

Any final thoughts on options to try?

Michael Cropper
  • 872
  • 1
  • 10
  • 28
  • oh there are better ways to install this... look into AdoptpenJDK – Eugene Jan 21 '20 at 21:26
  • Thanks Eugene, I'll have a read up on that. Couldn't find a simple wget / installer command on the website, looks like you need to go modifying yum sources. I'll have a read up on it anyhow. – Michael Cropper Jan 21 '20 at 21:34
  • Hmm, that doesn't quite seem to have resolved the issue. I'll update the above post with details... #Update1 @Eugene – Michael Cropper Jan 21 '20 at 21:38
  • 1
    What are your environment variables? Maybe you have something left over from the Java 7. --- Forget your current code for a second. If you create a new "Hello World" program that prints `LocalDate.now()` instead of `"Hello World"`, does it compile using plain `javac Test.java`? Does it run using plain `java -cp . Test`? – Andreas Jan 21 '20 at 21:43
  • Thanks for the suggestion @Andreas - I've just added #Update 2 above with more info – Michael Cropper Jan 22 '20 at 20:52
  • what do you see for javac, I mean like javac -version – Nigel Savage Jan 22 '20 at 21:11
  • @NigelSavage On the server: javac 1.8.0_232. On local machine, the build is done via Netbeans 8.2 IDE - javac isn't installed (Windows) – Michael Cropper Jan 22 '20 at 21:20
  • your comment "Tomcat 7 is setup" maybe the answer, are you familiar with Catalina Opts see https://stackoverflow.com/questions/11222365/catalina-opts-vs-java-opts-what-is-the-difference if not – Nigel Savage Jan 22 '20 at 21:36
  • @NigelSavage I've not come across that, let me take a read up about it and have a test - Also, in the last 15 minutes I've just spun up a brand new AWS server, got everything configured and deployed the application which magically 'just works'. Starting to think that the other server I'm having issues with needs binning off. Will post back once I've tested the Catalina Opts though as that may fix the immediate issue. – Michael Cropper Jan 22 '20 at 22:10
  • When you run `java -version` you run whichever Java is first on the PATH. Tomcat running as a service will have explicit reference to the Java to use, so it doesn't use the PATH. Or, for Linux, the Tomcat service runs as a difference user, so the PATH of that user might be different. All-in-all, Tomcat 7 (which is very old) is very likely running on that "previouos" Java 7 (which is still installed), and that is why `java.time.LocalDate` cannot be found. If the Tomcat Management webapp is deployed, log in and check for yourself, exactly which Tomcat and Java versions are involved. – Andreas Jan 23 '20 at 00:02
  • Thanks all for the help. Turned out that I wasn't going crazy after all - I was working with a crazy system! – Michael Cropper Jan 25 '20 at 20:38

1 Answers1

1

Solution... Bin off server control panels, they add complexity without providing any real benefits.

Turned out the issue was actually due to the way Tomcat was first installed via EasyApache3 on a cPanel system. At the time of installation, it looks like EasyApache3 decides that it's an awesome idea to hard code the java version in the Tomcat startup script. As such, when you update the Java version on the system, the Tomcat startup script actually keeps using the older version. I managed to find the script hunting around and update the code which solved the problem.

I mean, seriously, who does that??? #BangingHeadAgainstWall - The developer involved in building that for cPanel / EasyApache3 needs to have a strong word with their self!

Michael Cropper
  • 872
  • 1
  • 10
  • 28