How to target a specific version of java when making an uberjar using Leiningen
Asked Answered
V

2

9

I create a standalone jar using Lein uberjar. This works perfectly fine on my laptop which is running java 1.8. However the computers at my college run java 1.7.0_60.

Within my project.clj I have added :javac-options ["-target 1.7"] in order to compile to java 1.7, however this returns the same error as when that jar is compiled for java 1.8. The error being: Unsupported major.minor version 52.

Maybe the addition of :javac-options ["-target 1.7"] to my project.clj is having no influence on the version which is compiled, I am unsure, please help!

Veroniqueverras answered 16/7, 2015 at 11:3 Comment(2)
What does your project.clj look like? Do you depend on any libraries that may have been compiled with Java 8?Tyrrell
The problem was with one of the libraries used. Thanks!Veroniqueverras
J
5

Clojure currently compiles to Java classes that are backwards compatible to Java 1.6, so it is not the Leiningen javac options that are the issue. I ran into the same problem on one of my projects. The issue is that one of the libraries you are using is compiled for too new a Java version. When you build an überjar, Leiningen just copies the classes from your dependency jars into it, so you get whatever class file versions they have.

To solve this problem in my case I had to fork the dependency project on Github and make it build Java 1.6 compatible classes, and then make my Leningen project depend on the fork rather than the main project.

Jennajenne answered 13/5, 2016 at 12:58 Comment(1)
In my case I was able to roll back a dependency to a previous version which was compatible with my server's 1.7. However even the newer dependency version had :javac-options ["-target" "1.6"] in its project.clj so other than the release date of the package version and your uberjars crashing breaking on run I can't find an easy way to test compatibility.Bennir
A
0

It looks like you are using :javac-options wrong. Try to use this option as mentioned in Lein document: :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"].

Adze answered 17/7, 2015 at 5:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.