Unable to create a fat jar using sbt assembly (Lift 2.6 Final): no main manifest attribute

833 views
Skip to first unread message

Shafique Jamal

unread,
Jul 3, 2015, 10:21:54 AM7/3/15
to lif...@googlegroups.com
Hello all,

I'm trying to create a fat jar of my Lift 2.6 project, following the directions here:


I am getting the following error after creating the fat jar with 

./sbt assembly
java -jar target/scala-2.11/lift-jetty-fatjar-myproject-assembly-0.0.4.jar

the error:

no main manifest attribute, in target/scala-2.11/lift-jetty-fatjar-myproject-assembly-0.0.4.jar

I've looked on this mailing list for relevant posts, I and I found the following:


In the first link, there is the following:

"Lift does not use fat JARs because it is expected to be used in an environment
where you can build a WAR (which can include dependencies) or where you've got maven
available to resolve dependencies."

Does this mean that one cannot generate fat jars of a lift project? Is there any way around this?

Thanks,


Antonio Salazar Cardozo

unread,
Jul 3, 2015, 12:23:08 PM7/3/15
to lif...@googlegroups.com, shafiqu...@gmail.com
Matt Farmer will be able to confirm with certainty, but I believe anchortab uses a JAR
distribution with embedded Jetty, so it might be a good reference point.
Thanks,
Antonio

Matt Farmer

unread,
Jul 3, 2015, 8:37:13 PM7/3/15
to lif...@googlegroups.com
Antonio is correct. Check out my setup for Anchor Tab. 


Matt Farmer Blog | Twitter
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Nelson

unread,
Jul 4, 2015, 12:12:45 PM7/4/15
to lif...@googlegroups.com
Hi,

I'm not sure if this is related or not, but I had a problem with using the -jar option with this. I believe it is with JDK 7.

Try specifying the class you want to run instead of using -jar:

    java -cp target/scala-2.11/lift-jetty-fatjar-myproject-assembly-0.0.4.jar path.to.Main

Tim

Matt Farmer

unread,
Jul 7, 2015, 10:32:23 AM7/7/15
to Lift
My setup for Anchor Tab works well with JDK 7 – that’s what I was building on. If you’re running into issues with that setup in particular and can link me to a project I’m happy to take a look.


Matt Farmer Blog | Twitter
signature.asc

Tim Nelson

unread,
Jul 7, 2015, 12:01:46 PM7/7/15
to lif...@googlegroups.com
The problem I was running into was actually related to the number of files in the jar. This explains it:

Shafique Jamal

unread,
Jul 30, 2015, 12:16:30 PM7/30/15
to Lift, tnel...@gmail.com
Hello Antonio, Matt, Tim,

Thanks for your replies. I have tried the various suggestions, here are the results:

1. Try running the command without the -jar option

When I tried running the command without the -jar option, here is the error I got:
java target/scala-2.11/lift-jetty-fatjar-myproject-assembly-0.0.4.jar
Error: Could not find or load main class target.scala-2.11.lift-jetty-fatjar-myproject-assembly-0.0.4.jar

2. Try specifying the class you want to run instead of using -jar (Tim's suggestion above): 
java -cp target/scala-2.11/lift-jetty-fatjar-myproject-assembly-0.0.4.jar path.to.Main

I don't know where the Main class is located in the lift framework. Does anyone know?

3. Matt Farmer's achortab project. 
I don't fully understand what Start.scala is doing, but I copied that into my project and ran ./sbt assembly and then  

java -jar target/scala-2.11/lift-jetty-fatjar-myproject-assembly-0.0.4.jar

as before. I got the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler
at bootstrap.Start.main(Start.scala)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.Handler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more

Here is what I have in my build.sbt file:

    "com.h2database" % "h2" % "1.4.+" % "test",
    "net.liftweb"       %% "lift-webkit"        % liftVersion        % "compile",
    "net.liftmodules"   %% "lift-jquery-module_2.6" % "2.8",
    "org.eclipse.jetty" % "jetty-webapp"        % "9.1.4.v20140401"  % "container;provided",
    "org.eclipse.jetty" % "jetty-plus"          % "8.1.7.v20120910"  % "container,test", // For Jetty Config
    "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container,test" artifacts Artifact("javax.servlet", "jar", "jar"),
    "org.specs2"        %% "specs2"             % "2.3.12"           % "test",
    "net.liftmodules" %% ("ng_"+liftEdition)    % "0.6.4"            % "compile",
    "net.liftmodules" %% ("ng-js_"+liftEdition) % ("0.2_"+ngVersion) % "compile",
    "net.liftweb" %% "lift-squeryl-record" % liftVersion % "compile",
    "org.mortbay.jetty" % "jetty" % "6.1.26",
    "org.mortbay.jetty" % "jetty" % "6.1.22" % "container",
    "org.postgresql" % "postgresql" % "9.2-1003-jdbc4" % "compile",
    "net.liftmodules" %% "extras_2.6" % "0.4-SNAPSHOT",
    "ch.qos.logback" % "logback-classic" % "1.1.+",
    "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"

I should note that in order to get ./sbt to compile successfully using this approach to create a fat jar, I've have to comment out my tests and the RunWebApp.scala file in src.test.scala. I don't know why.

Would anyone have any more suggestions? Many thanks.

Matt Farmer

unread,
Jul 30, 2015, 12:20:08 PM7/30/15
to Lift
Hi Shafique,

I notice that you have “container” and “provided” specified alongside your jetty dependencies below. If you specify them as such then the jetty classes aren’t available to your runtime and Start.scala won’t work for you. Essentially Start.scala is bootstrapping and booting up the Jetty server, so you need those classes available at runtime, not just to the container plugin.

Note how I declared Jetty for Anchor Tab:


Matt Farmer Blog | Twitter

Tim Nelson

unread,
Jul 30, 2015, 2:05:06 PM7/30/15
to Lift, ma...@frmr.me
Hi Shafique,

To answer question 2, Lift does not have a main class. You'd need to write one yourself. Here [1] is anchortab's Start class. You'd need something like that.

Tim

Shafique Jamal

unread,
Sep 28, 2015, 4:32:12 PM9/28/15
to Lift, ma...@frmr.me
Hello all,

Thanks for your help with this. With some additional offline help from Matt Farmer, this is now working. SBT assembly does not include the webapp directory in the .jar file. 

JAR creation can be done using a package script like this one: https://github.com/anchortab/anchortab/blob/master/package.sh

Line 10 adds webapp to the JAR.

Cheers,
Reply all
Reply to author
Forward
0 new messages