javamacosscalajava-7xsbt-web-plugin

How to completely remove jdk 1.8 from Macbook? Scala Webapps Project


Thanks for reading my question. I've been struggling with this for more than 8 hours. On my macbook, I had JDK 6, 7, and 8 installed with 8 being default. I had a need this morning to create a scala/sbt webapp project (to package to a .war) to deploy on tomcat7 for a simple test application.

Only Requirement: Project must be able to run on JRE 1.7 & Tomcat 7

I have not been able to do it because of Unsupported major.minor and countless other problems with versioning and terrible giter8 templates.

Here's my current dilemma:

Followed all the steps in "Starting From Scratch" section up until sbt jetty:start jetty:join. (Skip to last code snippet for error): https://github.com/earldouglas/xsbt-web-plugin/blob/master/docs/3.0.x.md

Here's my java home and version:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
$
$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

Here's my build.sbt:

scalaVersion := "2.11.6"

libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"

enablePlugins(JettyPlugin) 

Here's my project/build.sbt:

addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "3.0.3")

Here's my project/build.properties:

sbt.version=0.13.8

servlet.scala and web.xml are exactly as they are in the link.

Here's my project structure:

.
├── build.sbt
├── project
│   ├── build.properties
│   └── build.sbt
└── src
    └── main
        ├── scala
        │   └── servlets.scala
        └── webapp
            └── WEB-INF
                └── web.xml

6 directories, 5 files

Here's the BANE OF MY EXISTENCE:

$ sbt jetty:start jetty:join
[info] Loading project definition from /Users/dan/Projects/temp/ssltester/project
[info] Updating {file:/Users/dan/Projects/temp/ssltester/project/}ssltester-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to ssltester (in build file:/Users/dan/Projects/temp/ssltester/)
[info] Updating {file:/Users/dan/Projects/temp/ssltester/}ssltester...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/dan/Projects/temp/ssltester/target/scala-2.11/classes...
[info] Packaging /Users/dan/Projects/temp/ssltester/target/scala-2.11/ssltester_2.11-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[info] starting server ...
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/jetty/runner/Runner : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
[success] Total time: 3 s, completed Nov 7, 2017 6:58:47 PM
[success] Total time: 0 s, completed Nov 7, 2017 6:58:48 PM
[info] waiting for server to shut down...

**Could someone please point out to me what's wrong? ** I completely deleted the java 1.8 jdk directory. Since it says version 52 (jdk 8) I don't know where it's coming from. jdk 7 should be 51, jdk 6 should be 50

If you're in Denver, I'll buy you a beer (if you're over 21) otherwise it's soda for you kid! :-)


Solution

  • Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/jetty/runner/Runner : Unsupported major.minor version 52.0
    

    My guess is that the version of Jetty that you're using was compiled for Java 8, which won't work if you're using Java 7. In xsbt-web-plugin 3.0.x, the default Jetty version is 9. Based on this table, you might want to try Jetty 8 (or older) instead.

    Try adding this to your build.sbt:

    containerLibs in Jetty := Seq("org.mortbay.jetty" % "jetty-runner" % "8.0.0.v20110901" intransitive())
    

    Since your requirements include being able to run your project under Tomcat, you may prefer to use Tomcat instead of Jetty. The default version of Tomcat is 8, which looks like it should work with Java 7 according to this table.

    To switch to Tomcat, change enablePlugins(JettyPlugin) to enablePlugins(TomcatPlugin) in your sbt configuration, and change jetty:start jetty:join to tomcat:start tomcat:join at the sbt prompt.