Java 6 service using/calling java8 library - java

Our service still uses Java 6 for compile and run. We need to use a library that is compiled with Java 8. Upon including the dependency in gradle we as expected see errors such as "class file has wrong version"
For android development gradle has something like gradle-retrolambda. Is there any generic gradle client that helps convert this library's bytecode compatible to java 6? or is there any other option other than our service upgrading to java8?
Thanks!

Related

The type java.time.Duration cannot be resolved when using OkHttpClient v3.12.x on Java 7

I'm developing for a project which is compiled for Java 7.
In this project I use OkHttpClient v3.12.13, which is compatible for Java 7 (as stated here). However these lines produces an error in the Eclipse editor:
private static final OkHttpClient GLOBAL_OK_HTTP_CLIENT = new OkHttpClient.Builder()
.readTimeout(10, TimeUnit.SECONDS)
.build();
The error is this:
The type java.time.Duration cannot be resolved. It is indirectly referenced from required .class files
This error is only shown by the editor. Indeed, when I compile my project using CLI (outside Eclipse) I don't get any error for that implicit reference to the java.time package.
I'm aware that in Java 7 there is no java.time package. Indeed, I'm not using it in my code, it's just implicitly referenced by the OkHttp library (as the error message says).
Is there a way to fix this error on Eclipse?
This is how I configured compiler compliance on Eclipse:
Note that I can't upgrade to newer Java versions.
The java.time classes are built into to Java 8 and later. You are deploying your app to Java 7. That version of Java lacks the java.time.Duration class invoked by your code calling a library.
You claim that library supports Java 7. If that is true, the library must have a switch to avoid using classes not available in Java 7.
You have improperly configured your IDE to allow programming in a later version of than the version on which you deploy. That is a problem you should fix. If deploying on Java 7, then compile for Java 7. See Question, how do I get eclipse to use a different compiler version for Java?.
Of course, the best solution is to migrate to a modern version of Java. Java 7 reached end-of-life in 2015-04. I highly recommend moving to a long-term support (LTS) version. Currently that would be Java 8 and Java 11.
If it were your own code using the java.time classes, I would suggest adding the ThreeTen-Backport library to your project. That library provides most of the java.time functionality with nearly identical API for use with Java 6 and Java 7. But I am guessing that would not satisfy your library in question, though you might want to verify.
Same issue I was facing, Changing the version of selenium in pom.xml worked for me. Changed version from 4.1.0 to 3.141.59

Can a java 8 project depend on a java 11 dependency in gradle

I have a project in Java 8 and attempting to utilise a library written in Java 11. I am getting an error:
class file has wrong version 55.0, should be 52.0
Is this something that is basically not possible or is there some Gradle configuration which allows a Java 8 project to use a library written and compiled to Java 11?
The short answers is YES, you can use a Java 11 dependency in a Java 8 project.
The following error class file has wrong version 55.0, should be 52.0 happens when you are trying to load a Java class compiled with Java 11 in a Java 8 Runtime Environment, the version of the compiled class is incompatible with older runtime environment versions.
To be able to run your Java 8 project with the Java 11 dependency, you will need to run your project in a Java 11 Runtime Environment, in most cases this is possible without the need of changes to the source code (sometimes you will need to add explicitly some dependencies that were removed from Java 11 like Java EE and Corba modules).

How to use a java 8 library with android?

I'm trying to use a library that uses java 8 in my android project. I cannot find a way to make this work. I've tried to use retro lambda but it has not helped. I keep getting the error: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version(0034.0000)
I've researched this and learned it's because there is java 8 syntax in the included library. I've been compiling with java 8 sdk and am using android studio 08.2. Help!
The library is:https://github.com/robrua/Orianna
Solution 1
Wait for android to support Java8.
Solution 2
Use an earlier version of the library that isn't Java8 and/or ask the developer of the library to provide one/ the last Java6 (or Java7 for kitcat upwards) library.
Solution 3
This is some kind of hack and I haven't tested or even used it!
Use retrolambda to backport the Java8-bytecode to Java6. On the homepage of retrolambda you find some documentation about it.
Downloads of retrolambda are here.
Probably you will have to unzip the library jar to a folder and the run a command like the following:
java -Dretrolambda.inputDir=<extracted_classfiles>
-Dretrolambda.classpath=<extracted_classfiles>
-Dretrolambda.bytecodeVersion=50
-javaagent:retrolambda.jar
-jar retrolambda.jar
Maybe you have to extend the classpath depending on the dependencies of the library.
Then you have to copy the resulting jar-file into your android-project's lib folder.
It is also possible to program Java8 for android.
If retrolambda doesn't work maybe you can find another tool to backport Java8-bytecode to Java6-bytecode.

Google App Engine's SDK compiles JSPs to class format 52.0, too high for server

I'm facing a problem where Eclipse and the App Engine SDK are building JSPs with class format 52.0, which subsequently fails to deploy as the server only accepts java 1.7 classes.
I've seen a bunch of workarounds that tell me to use a 1.7 JVM to start Eclipse. However, this is not possible due to a corresponding client application already heavily using Java 8 features.
Is there a way to get Eclipse to either:
Compile JSPs using 1.7 class formats?
or, failing that, to use a 1.8 compiler, runtime, and rt.jar to suggest for, build, debug, and run a standalone Maven project?

Converting Java to .NET library using IKVMC - Warning IKVMC0108: not a class file

There is Java tool (it is called Mallet)
http://mallet.cs.umass.edu/download.php
which I want to use in my .NET project.
To convert this tool to .NET library at first I've tried to build it in single .jar file using Apache Ant. I've done everything corresponding to instructions at link above.
Download Developer Release from Mercurial repository.
Download Apache Ant, install JDK, set JAVA_HOME var to use Apache Ant.
Using Ant I've built single mallet.jar file.
And then I would to convert mallet.jar to .NET library using IKVMC.
When converting, I've got a lot of warnings such as:
Warning IKVMC0108: not a class file "cc/mallet/util/tests/TestPriorityQueue$1.cl
ass", including it as resource
(class format error "51.0")
Despite of these warnings, mallet.dll was created. But when I try to reference to it from my .NET project, it looks "empty". It has not any classes or namespaces. I don't forget to reference to IKVM.OpenJDL.Core.
And this is unusual that I can't find any same problems in Google.
I think that problem is in warnings. And I have never worked with Ant and I don't understand all process exactly.
The class format version 51 was introduced with Java 7.
IKVM most likely doesn't support that version yet and the file name you quote (cc/mallet/util/tests/TestPriorityQueue$1.class) points at an anonymous inner class of TestPriorityQueue that certainly is needed for the library to work correctly.
My suggestion: compile Mallet using an older JDK or at least using the -source and -target switches set to 6 (to ensure that it's compile for Java 6).
FYI v8.1 (currently in RC) of IKVM supports Java 8:
http://weblog.ikvm.net/2015/08/26/IKVMNET81ReleaseCandidate0.aspx
http://sourceforge.net/p/ikvm/mailman/message/34502991/

Categories

Resources