Using JJWT on JDK 1.6 - java

On the main page I noticed that JJWT is supposed to run on all JDK, which - since our project for all sorts of reasons is still stuck on v1.6 - sounded great.
With the last version maven retrieves however, the class version is not compatible.
And afterwards in the build wiki I noticed it specifies version 7.
Anyone have a clue what does run on v1.6.
Can I use an older version, or should I compile it myself maybe.

On the main page I noticed that JJWT is supposed to run on all JDK ...
That is definitely incorrect / inaccurate. The initial commits for the JJWT project were for JDK 1.6. And I can see that the code uses generics, so compiling / running for earlier than JDK 1.5 will be impossible.
The POM.xml file for the latest version of the project sets the source and target version for the project to JDK 1.7. So certainly the artifacts that a standard build will generate now will NOT run on a Java 6 platform. The class file version will be too recent for a Java 6 JVM to understand.
Now you could try changing the JDK level to 1.6 in the POM file in the HEAD version. However, the JDK version for JJWT was bumped past 1.6 four years ago, so there are liable to be build issues if you wind back. (The developers could have introduced Java 7+ dependencies; e.g. using try with resources syntax or Java 7+ APIs.)
A better idea would be to use an old version of JJWT. You should be able to figure out what version you need to use (or build) for JDK 1.6 compatibility by looking at the project's git history on Github. Look at the relevant changes to the POM file and when they happened. I think it is version 0.9.0 or thereabouts.
Of course a better solution would be "unstick" your project. JDK 1.6 is 8 years past its end of life, and 3 years past the end of Oracle's JDK 1.6 (paid) extended support.

Related

Do I downgrade my JDK or upgrade my gradle?

I am currently using Gradle 3.0, which supports JDK 9. I tried to download JDK 9 from Oracle's official website but you need an account for the archived versions (they require a company name and a work phone, none of which I can provide). My version of JDK is 15.0.1. As far as I know, the latest version of Gradle supports it. However, I'm not sure how to update Gradle in my workspace. Would updating it cause any errors since it's a huge gap between the versions?
For reference, the older version of Gradle came with the mod developer kit of the forge. I am currently working on the 1.8.9 version of Minecraft. I am using IntelliJ, not Eclipse. I apologize if I didn't structure my question properly.
IntelliJ IDEA has JDK downloader that offers multiple JDK versions/vendors. You can use JDK 1.8 for Gradle 3.0 or JDK 11 for Gradle 5.0+:
Just Install sdkman.io
Then upgrading the Gradle/maven/jdk and many other JVM project is as easy as running a command.
You can also switch between versions in a very convenient way.

Java versions confusion

I want to install Java on a few different servers for running a third party service on tomcat.
I am not a Java developer and I got a bit confused when I began searching for the installer.
I checked the different Java versions and their long term support dates.
It seems that Java 11 JDK is - LTS so i decided to use it.
But when I was trying to find a runtime version (JRE?) since this is the version I am supposed to install on the server(?) I only found Java JRE 8.X.X, and this got me confused.
There is no higher major version of the JRE?
How does it work if you use the JDK 11 or even 14-15 as a developer and then use Java 8 JRE on your deployed servers?
Maybe the JDK holds inside of it the Java 8 JRE version?
Or do you actually need to install the JDK version on the servers instead?
The JRE is a subset of JDK. It contains everything needet to run Java applications but no support for development. So, if you need a JRE, a JDK is also good, although it conatins much stuff that you will not need.
Normally, for executing a Java application, you need a JRE with the same version or higher than the JDK used for development. But the developer can advise the compiler to generate code for a lower version. If he does so, he cannot use the features of the higher versions. For example the compiler of JDK 1.8 can produce code for JRE 1.6. You should consult the manual, to see which old versions are supported by the compiler of a specific version.
After some research,
It seems there is no separate JRE section anymore.
Also JDK 11 for production is not free and I guess this is an ongoing trend for the near future.
On a side note there is the open JDK 11 version but it does warn you about outdated security updates.
So basically in my case sticking to updated Java JRE 8 version is good enough for the near future.

Our company is planning to move towards AdoptOpenJdk 11 with Wildfly 10 running on it

Our company is planning to move towards AdoptOpenJdk 11 from Oracle JDK8 with Wildfly 10 running on it. All the code and wildfly server will be same(written and supported by JDK8) and since java is backward compatible, I think that it should work theoretically, but are there any issues that we have to be aware of?
There are a lot of updates from JDK 8 to JDK 11. I would recommend just moving to AdoptOpenJdk 8 in the short term. Your specific code may be ok, but you also have a huge set of dependencies that may be using something that needs updated. For example, what is your build tool? Gradle needed to be updated because it needed a newer version of ASM. Are you using JAX-RS? Jersey 2.27 doesn't work on Java 11.
JavaEE is in a weird place right now because Oracle basically dumped it on the Eclipse foundation (now called JakartaEE). It will take a little while for it to be sorted out.
I have migrated from openjdk-8 to openjdk-11.
Steps I follow:
1. Add missing Java dependencies in jdk11
2. Upgrade/remove supported plugins (Need to upgrade ASM to 7.1, cglib or other byte manipulation libs)
3. Change JAVA_OPTIONS related to GC.
4. Wildfly support for java11
More details on libs versions check the link

Fast-ClassPath-Scanner does not work with java 6 runtime?

Fast-ClassPath-Scanner
https://github.com/lukehutch/fast-classpath-scanner using latest version.
On executing(get names of all classes in war which includes all jars and classes)
new FastClasspathScanner(basePackage).scan().getNamesOfAllClasses()
getting:
unsupportedclassversion error with jre 6
Please provide a solution to it or alternative to perform same.
FastClasspathScanner is compiled for java 1.7
When you try to load it in a 1.6 (JRE6) environment it fails with an UnsupportedClassVersionError. This error indicates that the class version (here 1.7) is not compatible with the JVM version (here 1.6).
Java 7 is not backwards compatible with Java 6. You could try to build the FastClasspathScanner library yourself unter 1.6 (not sure if that's possible). Or upgrade your project to Java 7.
Correct, I am the author of FastClasspathScanner, and it's not a goal to get this working with JRE6. However, patches for supporting 1.6 are welcome.

Create Jar Compatible With Java 7 With IntelliJ Using JDK8

I am using JDK8 on my normal desktop and I have a separate linux box that I am trying to run the Java program on.
The problem I'm running into is that the linux box is running jdk7, so the computer has JRE7 basically that it is running off of. My question is, is it possible to create a jar file in JDK8 that will be compatible with java 7?
I'm using IntelliJ to compile. I tried to compile in 1.7, but it gave an error when I did end up trying to do it. I compile it here:
In 1.8 it works fine to compile, but when I try to compile in 1.7 it doesn't work.
I know the short answer is to update the linux to JRE 8. But I am curious, is there a way to make it backwards compatible? Or is the other answer to simply install JDK7 on the desktop in order for it to run on the linux box using JRE7?
Java programs built with JDK 8 will only run on machines running JRE 8 (or higher).
I found this when trying to compile classes on my local Linux machine (using JDK 8) and deploying to a remote server running JRE 7. The classes just wouldn't work (like you're finding).
If you want to use JRE 8 on linux, I recommend using the oracle-java8-installer package from webupd8team. Installation instructions found here (assuming Debian based distro).
If you want to compile to JDK 7, it's not good enough to only have JDK 8 installed and pick to compile 1.7. You need JDK 7 installed to and restage your project to use JDK 7.
The thing you have to remember is that the difference between JRE/JDK versions is not just the extra features developers can use (e.g Lambda functions) but it's also that the JRE itself is improved (efficiency, garbage collection, etc.).
As a extreme example: If you wrote code that only used JDK 1 features but compiled it using JDK 8, it wouldn't run on a machine running JRE 1 because the Java classes had been compiled with JRE 8 in mind.
Do note though, that if you're Java Code uses only features from JDK 7 or 6 etc., you might think it good practice to compile using the minimum JDK required to allow for compatibility with more machines. Well...you'd have that compatibility but at a cost of using inefficient, out of date, possibly vulnerable compiled classes (At little extreme, but you get my point).
Are you using any new Java 8 features? Because if you are, this means you cannot build the project against the JRE7.
If you are not using any Java 8 features, you can build to Java 7 most easily by downloading the JDK7 and switching the project to use that instead of the JDK8.
You should also set project language level to 1.7 (and module language level(s) as well, if they're different). It's done in Project Structure settings dialog. After that the project should compile.
Note that you shouldn't use any of the APIs that appeared in 1.8, but such usages will most likely be highlighted in the editor.

Categories