Java versions and Maven
-
I'm using Maven. I have a JDBC driver from Microsoft, version 4.2, and I've added it as a Maven dependency to the local repo. My build machines have Java 8, but I'm set to target Java 7 in my pom.xml . I'm getting the following error:
java.lang.UnsupportedClassVersionError: com/microsoft/sqlserver/jdbc/SQLServerDriver : Unsupported major.minor version 52.0
Major/minor 52.0 is Java 1.8, right? Why is it unsupported? My target was 1.7, which is 51.0. Do I have to actually compile using JDK 1.7?
-
@Yamikuronue said in Java versions and Maven:
Major/minor 52.0 is Java 1.8, right? Why is it unsupported? My target was 1.7, which is 51.0. Do I have to actually compile using JDK 1.7?
Bytecode version 52.0 is Java 8. It means that that code was compiled with Java 8 with Java 8 as a target platform. It won't load into earlier versions (and I forget why the incompatibility is actually there). Your options are to either rebuild that code with Java 7 as target version (default if you compile with 7) or upgrade the version of Java that is trying to use the class.
Java 8 will load older versions. The other kind of compatibility is the crazy kind.
-
@dkf OH! It's the other way around? I thought it was saying it didn't support 52, but it's saying it prefers 52?
-
@Yamikuronue It's saying that
com.microsoft.sqlserver.jdbc.SQLServerDriver
was compiled with Java 8 and so won't load into Java 7 (or otherwise less than 8).
-
@dkf Ok. I will compile my code for Java 8 then :D
-
Oh. We don't have java 8 on this agent, and the other agent doesn't have maven. This sandbox is in terrible shape XD
-
@Yamikuronue Both of those statements are
-
@JazzyJosh All the machines were meant to be upgraded to Java 8, but this one only has 7, so someone overlooked it I guess. The other one is brand new, someone forgot to put Maven on it.
I don't use my sandbox system often
-
@Yamikuronue said in Java versions and Maven:
someone forgot to put Maven on it.
*cough* Vagrant *cough*
-
OK, so this isn't related to your problem (probably), but...
Java warns you when you try targetting a lower version when you're compiling things which looks like this:
warning: [options] bootstrap class path not set in conjunction with -source 1.7
The reason you get this is because Java reorganizes its internals between versions and if you compile against the 1.8 class library while targetting a lower version, you may end up with a program that won't actually run on said lower version despite targetting that version.
What it's asking you to do is tell it where the 1.7
rt.jar
file is (which is actually from the JRE not the JDK) using the-bootclasspath
option. I'm sure Maven has the option for that, but I don't recall what it is.
-
@Yamikuronue said in Java versions and Maven:
All the machines were meant to be upgraded to Java 8, but this one only has 7, so someone overlooked it I guess.
If you're stuck with Java 8 because of those classes you depend on, you probably ought to set that requirement in stone in the POM:
-
@dkf I tried that. No dice. The JDBC driver won't work under 7. So I have to compile for 8. So I'm on hold waiting for my install of 8.
-
@Yamikuronue said in Java versions and Maven:
The JDBC driver won't work under 7.
Yes, we already learned that. I was advocating for it being the other way round, forcing the use of Java 8 so that the error happens earlier and more clearly instead of a frankly gnostic message about bytecode versions. You'll still have to sort out your system config; a Java 8 class really won't ever run with a Java 7 JRE.
-
@dkf oh, gotcha. The build system asks what version of Java you want to run the Maven executable under, so it's configured there; I've set that to 8, and now it won't run because none of the agents have both Maven and 8, so it's pretty explicit about the reason ATM.
but I also should go revert the change to the POM to get it to to compile as 7
-
@Yamikuronue Yes. If it's bust on Java 7, there's no real point in going on. If you had some components that could be built with Java 7, it might be worth splitting out, but that's a lot of work by comparison with upgrading the JDK, even with a fairly sclerotic process.
-
@dkf Yeah, this is an automated test suite so... no real point here. But I've been asked to move to Java 8 anyway so, carpe diem. Otherwise I'd just grab an older driver jar.