java.lang.UnsupportedClassVersionError when following tutorial - java

I'm trying to use Play! but I always get an error when trying to run a project: [error] java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0
When I do java -version or javac -version, it confirms I'm using Java 8 by outputting 1.8.0_45. I don't understand why this error happens, the docs says I NEED java 8 for the latest Play! version, the project has a dependency to Play! 2.4.2.
I followed the documentation: installed activator, added it to the path, generated a new project form the template 'java-play-intro' but when i type activator in my project directory, I always get the error above. I tried to use the update-alternative command to use java 6 and then 7 but the error is exactly the same.
BUT when I use activator ui it works fine !
How is this possible? Am I always supposed to use the UI?

Most probably the script you are starting, uses the JAVA_HOME environment variable and not the JDK binaries that can be found on your PATH.

Related

OpenCV build from source fails with Java 11: warning: target release 11 conflicts with default source release 18

I’m working on a Java application that runs Java 11. I’ve chosen Java 11 because it’s the the last Java version with LTS.
I’m using OpenCV in this Java application and am using libraries from the contrib modules. I’m using Homebrew to install OpenCV with the Java bindings and the contrib modules.
The first thing I tried was to install OpenCV from source without specifying the Java target version. When I did this, OpenCV installed correctly, but when I tried to use it in code, I got the following error:
class file has wrong version 61.0, should be 55.0
I take this to mean that because OpenCV was compiled via Java 17, I can’t use it in my Java 11 code. It’s also worth mentioning that because I’m using Maven with my Java project, I first export the OpenCV JAR into a local Maven module via something like mvn install:install-file -Dfile=/usr/local/Cellar/opencv/4.5.5_1/share/java/opencv4/opencv-455.jar. I’m using OpenJDK 11 as my JRE for this export.
I’m also using OpenJDK 11 as my default JDK on my Mac (java -version and javac -version both return OpenJDK 11). So I was a bit surprised to see this error.
So to solve it, I’ve been trying to install OpenCV with the flag -DOPENCV_JAVA_TARGET_VERSION=11. However, when I do this, I get the following error:
[ 11%] Generating opencv-455.jar
cd /tmp/opencv-20220410-81173-p3o3uo/opencv-4.5.5/build/modules/java/jar/opencv && /usr/local/bin/ant -noinput -k jar
Picked up _JAVA_OPTIONS: -Duser.home=/Users/dpapp/Library/Caches/Homebrew/java_cache
Buildfile: /private/tmp/opencv-20220410-81173-p3o3uo/opencv-4.5.5/build/modules/java/jar/opencv/build.xml
[tstamp] Honouring environment variable SOURCE_DATE_EPOCH which has been set to 1640404407
jar:
[javac] Compiling 280 source files to /private/tmp/opencv-20220410-81173-p3o3uo/opencv-4.5.5/build/modules/java/jar/opencv/build/classes
[javac] warning: target release 11 conflicts with default source release 18
Target 'jar' failed with message 'Compile failed; see the compiler error output for details.'.
BUILD FAILED
/private/tmp/opencv-20220410-81173-p3o3uo/opencv-4.5.5/build/modules/java/jar/opencv/build.xml:14: Compile failed; see the compiler error output for details
This error makes it sound like OpenCV requires at least JDK 18, which doesn’t sound right to me. Is there a minimum JDK for each OpenCV version? Should I be using OpenCV 3 instead? Any help is greatly appreciated, thank you!
I partially figured out what's going on here.
As a prereq for running brew install opencv, I ran brew install ant. brew install ant installs the latest OpenJDK (OpenJDK 18 at the time of writing) and ignores the Java home path set on my machine. This causes brew install opencv to try to install OpenCV with Java 18 while the target is set to 11, which throws an error.

ERROR EvoSuite - Fatal crash on main EvoSuite process

I'm getting the following error when I try to run EvoSuite. I even provided the complete path to jdk but still the error is not resolved. Please help me out.
C:\Users\XYZ\Documents\Tutorial_Stack>java -jar evosuite-1.0.6.jar -Dtools_jar_location="C:\Program Files\Java\jdk-11\lib"
[MASTER] 21:56:45.409 [main] ERROR EvoSuite - Fatal crash on main EvoSuite process. Class using seed 1541559405405. Configuration id : null
java.lang.RuntimeException: Did not manage to automatically find tools.jar. Use -Dtools_jar_location=<path> property
at org.evosuite.runtime.agent.ToolsJarLocator.getLoaderForToolsJar(ToolsJarLocator.java:105) ~[evosuite-1.0.6.jar:1.0.6]
at org.evosuite.classpath.ClassPathHacker.initializeToolJar(ClassPathHacker.java:58) ~[evosuite-1.0.6.jar:1.0.6]
at org.evosuite.EvoSuite.parseCommandLine(EvoSuite.java:156) ~[evosuite-1.0.6.jar:1.0.6]
at org.evosuite.EvoSuite.main(EvoSuite.java:302) ~[evosuite-1.0.6.jar:1.0.6]
I am not sure if Evosuite works with any other version of JDK except 8. The Evosuite beginner's tutorial states:
The first prerequisite for this tutorial is a working Java 8 JDK
installation and a command-line prompt, with java and javac on the
classpath.
To check if you are set up, fire up a terminal and try the following:
javac -version
If you have JDK installed, you will see an output similar to the following:
javac 1.8.0_51
Note: the last part of the version could be different
Another question: Are you using any IDE for this like IntelliJ or Eclipse? I had a similar problem and I resolved it by setting the module SDK to 1.8 on my IntelliJ project.

How to fix java.lang.UnsupportedClassVersionError in a Xamarin application? [duplicate]

After installing VS2015 in W10, and trying to compile a project which works perfectly in W7, I´m getting this error: Unsupported major.minor version 52.0.
I tried to installa Java7U80, Java7U79, Java8, changing classpath, and so on...
If you have multiple JDKs then remove them. Install JDK 8 the latest version and go to Visual Studio options => Xamrin and set the Java Development Kit Location to the JDK 8 path e.g C:\Java\JDK\jdk1.8.0_92.
Usually this error comes up, when your project compiles/runs against lets say Java 7, while referencing some dependency which is compiled against Java 8 (and uses Java 8 features).
Check your compiler level or your runtime configuration.

Unable to execute the program in hadoop

When I created a Jar and compiled in windows and tried to run in Hadoop. It's throwing an error while running this script
admin1#admin1:/usr/local/hadoop/conf$ hadoop jar wordcount.jar com.shailu.wordcount.WordCount input/wordcount output/wordcount
Error is:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/shailu/wordcount/WordCount : Unsupported major.minor version 52.0
Nothing wrong with ur execution,
Looks like there is a mismatch in the compile and the execute environment.
type "java -version" in both the environments , i.e. windows and hadoop(linux/unix)
My doubt is you have compiled the code in a higher version like 1.8, change it to 1.7 or so, you should be ok.
or while compiling choose the same java version as the hadoop environment have.
I have encountered such problem. You need keep the compiler consistently between windows and hadoop or hadoop compiler higher than windows'. See picture I screenshot from Internet(contain a little Chinese, you also can refence this website if you can open it: JDK compiler version mapping minor.major). I guess JDK1.8.x is mapping major.minor version 52.0.
JDK编译器版本-------------JDK compiler version
target参数----------------target parameter
十六进制 minor.major------hexadecimal minor.major
十进制 minor.major--------decimal minor.major
不能带 target 参数--------can't add target parameter
默认为--------------------default

UnsupportedClassVersionError when running Ant from eclipse

I'm trying to run an ant script from eclipse but it fails with the following message:
BUILD FAILED
project_path/build.xml:5:
java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main :
Unsupported major.minor version 51.0
However, when I run this from command line (./ant) it runs as expected.
Environment info:
OS: Linux Mint 64
Eclipse: Juno (4.2.1)
JDK: Oracle 1.7.0_11
Ant (command line): 1.8.2
I've also set the "Ant Home" (within eclipse settings) to be the same as the one I use from command line.
I've searched a lot on this issue but I can't seem to find anything that helped, I can try to uninstall all java (jdk/jre) I currently have installed, and then reinstall java 7, but I prefer not to take this route.
Any ideas?
Thanks!
UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 51.0
This suggests there's some mix up between versions - Ant is trying to run the Java 7 javac on a Java 6 JVM. Have a look at your project properties, builders, Ant Builder, and check the classpath section. On my Eclipse with a newly-created Ant Builder I have the tools.jar from my 1.7 JDK listed under user entries -> additional tasks and support. If you have the same, but your Eclipse is itself running on Java 6 then it won't work. You can find out which Java Eclipse itself is running on via the "about Eclipse" box under installation details -> configuration. This may not be the same as the version of Java that your project is configured to use.
Another thing that might fix it is to go to the JRE tab in the ant builder settings and tell it to run in a separate JRE rather than running within the Eclipse process.
Your Eclipse ant task is trying to run the Java7 JDK compiler using a pre-Java7 JDK/JRE. Make sure you use a Java7 JRE to run Eclipse.
generally if you compile Java program in Java 1.7 it will create class file with major version 51.0 and if you run that on lower java version you will get
java.lang.unsupportedclassversionerror unsupported major.minor version 51.0
check this post for more details on the same

Categories

Resources